2012-07-12 01:31:19 +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-10-05 03:32:38 +00:00
|
|
|
// The minimum sizes for the auto-resize panel code.
|
2012-10-08 06:14:55 +00:00
|
|
|
const PANEL_MIN_HEIGHT = 100;
|
2012-10-05 03:32:38 +00:00
|
|
|
const PANEL_MIN_WIDTH = 330;
|
|
|
|
|
2012-12-07 07:38:46 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "SharedFrame",
|
|
|
|
"resource:///modules/SharedFrame.jsm");
|
|
|
|
|
2012-07-12 01:31:19 +00:00
|
|
|
let SocialUI = {
|
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() {
|
|
|
|
Services.obs.addObserver(this, "social:pref-changed", false);
|
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-11-15 03:57:28 +00:00
|
|
|
Services.obs.addObserver(this, "social:recommend-info-changed", false);
|
2012-10-30 20:10:04 +00:00
|
|
|
Services.obs.addObserver(this, "social:frameworker-error", false);
|
2012-12-08 04:13:27 +00:00
|
|
|
Services.obs.addObserver(this, "social:provider-set", false);
|
2012-07-15 23:12:13 +00:00
|
|
|
|
2012-07-18 18:40:05 +00:00
|
|
|
Services.prefs.addObserver("social.sidebar.open", this, false);
|
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
|
|
|
|
2013-02-07 14:36:31 +00:00
|
|
|
gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler, true, true);
|
2012-06-22 22:01:34 +00:00
|
|
|
|
2012-10-03 23:11:52 +00:00
|
|
|
// Called when we enter DOM full-screen mode.
|
2012-11-13 03:52:06 +00:00
|
|
|
window.addEventListener("mozfullscreenchange", function () {
|
|
|
|
SocialSidebar.update();
|
|
|
|
SocialChatBar.update();
|
|
|
|
});
|
2012-10-03 23:11:52 +00:00
|
|
|
|
2012-07-12 01:31:19 +00:00
|
|
|
Social.init(this._providerReady.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called on window unload
|
|
|
|
uninit: function SocialUI_uninit() {
|
|
|
|
Services.obs.removeObserver(this, "social:pref-changed");
|
2012-07-15 23:12:13 +00:00
|
|
|
Services.obs.removeObserver(this, "social:ambient-notification-changed");
|
|
|
|
Services.obs.removeObserver(this, "social:profile-changed");
|
2012-11-15 03:57:28 +00:00
|
|
|
Services.obs.removeObserver(this, "social:recommend-info-changed");
|
2012-10-30 20:10:04 +00:00
|
|
|
Services.obs.removeObserver(this, "social:frameworker-error");
|
2012-12-08 04:13:27 +00:00
|
|
|
Services.obs.removeObserver(this, "social:provider-set");
|
2012-07-18 18:40:05 +00:00
|
|
|
|
|
|
|
Services.prefs.removeObserver("social.sidebar.open", this);
|
2012-09-27 00:40:18 +00:00
|
|
|
Services.prefs.removeObserver("social.toast-notifications.enabled", this);
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// Called once, after window load, once Social.jsm's provider has been set.
|
|
|
|
_providerReady: function SocialUI_providerReady() {
|
|
|
|
this._updateActiveUI();
|
|
|
|
this._updateMenuItems();
|
|
|
|
|
|
|
|
SocialChatBar.update();
|
|
|
|
SocialShareButton.init();
|
|
|
|
SocialMenu.populate();
|
|
|
|
SocialToolbar.init();
|
|
|
|
SocialSidebar.init();
|
2012-07-15 23:12:13 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// Social.provider has changed, update any state that depends on it.
|
|
|
|
// Note: this method is not called when Social.provider is first set, during
|
|
|
|
// the first window load.
|
|
|
|
_updateProvider: function () {
|
|
|
|
// XXX audit for handling nullness of social.provider
|
|
|
|
this._updateActiveUI();
|
|
|
|
this._updateMenuItems();
|
|
|
|
|
|
|
|
SocialChatBar.update();
|
|
|
|
SocialShareButton.updateProvider();
|
|
|
|
SocialMenu.populate();
|
|
|
|
SocialToolbar.updateProvider();
|
|
|
|
SocialSidebar.update();
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// The entire feature is being turned on/off.
|
|
|
|
_updateEnabledState: function () {
|
|
|
|
this._updateActiveUI();
|
|
|
|
SocialChatBar.update();
|
|
|
|
SocialSidebar.update();
|
|
|
|
SocialShareButton.updateButtonHiddenState();
|
|
|
|
SocialMenu.populate();
|
|
|
|
SocialToolbar.updateButtonHiddenState();
|
|
|
|
SocialToolbar.populateProviderMenus();
|
2012-07-23 03:49:28 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
_matchesCurrentProvider: function (origin) {
|
|
|
|
return Social.provider && Social.provider.origin == origin;
|
|
|
|
},
|
2012-06-22 22:01:34 +00:00
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
observe: function SocialUI_observe(subject, topic, data) {
|
|
|
|
// Exceptions here sometimes don't get reported properly, report them
|
|
|
|
// manually :(
|
|
|
|
try {
|
|
|
|
switch (topic) {
|
|
|
|
case "social:provider-set":
|
|
|
|
this._updateProvider();
|
|
|
|
break;
|
|
|
|
case "social:pref-changed":
|
|
|
|
this._updateEnabledState();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Provider-specific notifications
|
|
|
|
case "social:ambient-notification-changed":
|
|
|
|
if (this._matchesCurrentProvider(data)) {
|
|
|
|
SocialToolbar.updateButton();
|
|
|
|
SocialMenu.populate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "social:profile-changed":
|
|
|
|
if (this._matchesCurrentProvider(data)) {
|
|
|
|
SocialToolbar.updateProfile();
|
|
|
|
SocialShareButton.updateProfileInfo();
|
|
|
|
SocialChatBar.update();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "social:recommend-info-changed":
|
|
|
|
if (this._matchesCurrentProvider(data)) {
|
|
|
|
SocialShareButton.updateShareState();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "social:frameworker-error":
|
2013-01-24 10:14:36 +00:00
|
|
|
if (this.enabled && Social.provider.origin == data) {
|
2013-01-26 20:07:39 +00:00
|
|
|
SocialSidebar.setSidebarErrorMessage();
|
2012-12-08 04:13:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-07-23 03:49:28 +00:00
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
case "nsPref:changed":
|
|
|
|
if (data == "social.sidebar.open") {
|
|
|
|
SocialSidebar.update();
|
2013-01-21 04:38:35 +00:00
|
|
|
} else if (data == "social.toast-notifications.enabled") {
|
|
|
|
SocialToolbar.updateButton();
|
2012-12-08 04:13:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2013-01-07 20:42:02 +00:00
|
|
|
Components.utils.reportError(e + "\n" + e.stack);
|
2012-12-08 04:13:27 +00:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
},
|
2012-10-30 06:28:31 +00:00
|
|
|
|
2012-12-11 23:41:42 +00:00
|
|
|
nonBrowserWindowInit: function SocialUI_nonBrowserInit() {
|
|
|
|
// Disable the social menu item in non-browser windows
|
|
|
|
document.getElementById("menu_socialAmbientMenu").hidden = true;
|
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// Miscellaneous helpers
|
|
|
|
showProfile: function SocialUI_showProfile() {
|
|
|
|
if (Social.haveLoggedInUser())
|
|
|
|
openUILinkIn(Social.provider.profile.profileURL, "tab");
|
|
|
|
else {
|
|
|
|
// XXX Bug 789585 will implement an API for provider-specified login pages.
|
|
|
|
openUILinkIn(Social.provider.origin, "tab");
|
|
|
|
}
|
2012-06-22 22:01:34 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
_updateActiveUI: function SocialUI_updateActiveUI() {
|
2013-01-24 10:14:36 +00:00
|
|
|
// The "active" UI isn't dependent on there being a provider, just on
|
|
|
|
// social being "active" (but also chromeless/PB)
|
2013-02-07 14:36:31 +00:00
|
|
|
let enabled = Social.active && !this._chromeless &&
|
2013-01-29 18:12:13 +00:00
|
|
|
!PrivateBrowsingUtils.isWindowPrivate(window);
|
2012-12-08 04:13:27 +00:00
|
|
|
let broadcaster = document.getElementById("socialActiveBroadcaster");
|
2013-01-24 10:14:36 +00:00
|
|
|
broadcaster.hidden = !enabled;
|
2012-12-08 04:13:27 +00:00
|
|
|
|
|
|
|
let toggleCommand = document.getElementById("Social:Toggle");
|
2013-01-24 10:14:36 +00:00
|
|
|
toggleCommand.setAttribute("hidden", enabled ? "false" : "true");
|
2013-02-05 05:42:18 +00:00
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
// We only need to update the command itself - all our menu items use it.
|
2013-02-07 14:36:31 +00:00
|
|
|
let label = gNavigatorBundle.getFormattedString(Social.provider.enabled ?
|
2013-02-05 05:42:18 +00:00
|
|
|
"social.turnOff.label" :
|
|
|
|
"social.turnOn.label",
|
2013-02-07 14:36:31 +00:00
|
|
|
[Social.provider.name]);
|
|
|
|
let accesskey = gNavigatorBundle.getString(Social.provider.enabled ?
|
2013-02-05 05:42:18 +00:00
|
|
|
"social.turnOff.accesskey" :
|
|
|
|
"social.turnOn.accesskey");
|
|
|
|
toggleCommand.setAttribute("label", label);
|
|
|
|
toggleCommand.setAttribute("accesskey", accesskey);
|
|
|
|
}
|
2012-07-23 03:49:28 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
_updateMenuItems: function () {
|
|
|
|
if (!Social.provider)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The View->Sidebar and Menubar->Tools menu.
|
|
|
|
for (let id of ["menu_socialSidebar", "menu_socialAmbientMenu"])
|
|
|
|
document.getElementById(id).setAttribute("label", Social.provider.name);
|
2012-11-27 06:54:55 +00:00
|
|
|
},
|
|
|
|
|
2012-06-22 22:01:34 +00:00
|
|
|
// This handles "ActivateSocialFeature" events fired against content documents
|
|
|
|
// in this window.
|
|
|
|
_activationEventHandler: function SocialUI_activationHandler(e) {
|
|
|
|
let targetDoc = e.target;
|
|
|
|
|
|
|
|
// Event must be fired against the document
|
|
|
|
if (!(targetDoc instanceof HTMLDocument))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ignore events fired in background tabs
|
|
|
|
if (targetDoc.defaultView.top != content)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check that the associated document's origin is in our whitelist
|
2012-12-08 04:13:27 +00:00
|
|
|
let providerOrigin = targetDoc.nodePrincipal.origin;
|
2013-02-07 14:36:31 +00:00
|
|
|
let whitelist = Services.prefs.getCharPref("social.activation.whitelist");
|
|
|
|
if (whitelist.split(",").indexOf(providerOrigin) == -1)
|
2012-06-22 22:01:34 +00:00
|
|
|
return;
|
|
|
|
|
2013-01-24 10:14:36 +00:00
|
|
|
// If we are in PB mode, we silently do nothing (bug 829404 exists to
|
|
|
|
// do something sensible here...)
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(window))
|
|
|
|
return;
|
|
|
|
|
2012-06-22 22:01:34 +00:00
|
|
|
// If the last event was received < 1s ago, ignore this one
|
|
|
|
let now = Date.now();
|
|
|
|
if (now - Social.lastEventReceived < 1000)
|
|
|
|
return;
|
|
|
|
Social.lastEventReceived = now;
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// Keep track of the old provider in case of undo
|
|
|
|
let oldOrigin = Social.provider ? Social.provider.origin : "";
|
|
|
|
|
2012-06-22 22:01:34 +00:00
|
|
|
// Enable the social functionality, and indicate that it was activated
|
2013-02-07 14:36:31 +00:00
|
|
|
let provider = Social.activateFromOrigin(providerOrigin);
|
|
|
|
|
|
|
|
// Provider to activate may not have been found
|
|
|
|
if (!provider)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Show a warning, allow undoing the activation
|
|
|
|
let description = document.getElementById("social-activation-message");
|
|
|
|
let brandShortName = document.getElementById("bundle_brand").getString("brandShortName");
|
|
|
|
let message = gNavigatorBundle.getFormattedString("social.activated.description",
|
|
|
|
[provider.name, brandShortName]);
|
|
|
|
description.value = message;
|
|
|
|
|
|
|
|
let notificationPanel = SocialUI.notificationPanel;
|
|
|
|
// Set the origin being activated and the previously active one, to allow undo
|
|
|
|
notificationPanel.setAttribute("origin", provider.origin);
|
|
|
|
notificationPanel.setAttribute("oldorigin", oldOrigin);
|
|
|
|
|
|
|
|
// Show the panel
|
|
|
|
notificationPanel.hidden = false;
|
|
|
|
setTimeout(function () {
|
|
|
|
notificationPanel.openPopup(SocialToolbar.button, "bottomcenter topright");
|
|
|
|
}, 0);
|
2012-06-22 22:01:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
undoActivation: function SocialUI_undoActivation() {
|
2012-12-08 04:13:27 +00:00
|
|
|
let origin = this.notificationPanel.getAttribute("origin");
|
|
|
|
let oldOrigin = this.notificationPanel.getAttribute("oldorigin");
|
|
|
|
Social.deactivateFromOrigin(origin, oldOrigin);
|
2012-06-22 22:01:34 +00:00
|
|
|
this.notificationPanel.hidePopup();
|
2012-09-23 23:49:28 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
get notificationPanel() {
|
|
|
|
return document.getElementById("socialActivatedNotification");
|
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) {
|
|
|
|
containerParent.hidePopup();
|
|
|
|
}
|
2012-10-30 06:25:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
disableWithConfirmation: function SocialUI_disableWithConfirmation() {
|
|
|
|
let brandShortName = document.getElementById("bundle_brand").getString("brandShortName");
|
|
|
|
let dialogTitle = gNavigatorBundle.getFormattedString("social.remove.confirmationOK",
|
|
|
|
[Social.provider.name]);
|
|
|
|
let text = gNavigatorBundle.getFormattedString("social.remove.confirmationLabel",
|
|
|
|
[Social.provider.name, brandShortName]);
|
|
|
|
let okButtonText = dialogTitle;
|
|
|
|
|
|
|
|
let ps = Services.prompt;
|
|
|
|
let flags = ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0 +
|
|
|
|
ps.BUTTON_TITLE_CANCEL * ps.BUTTON_POS_1 +
|
|
|
|
ps.BUTTON_POS_0_DEFAULT;
|
|
|
|
|
|
|
|
let confirmationIndex = ps.confirmEx(null, dialogTitle, text, flags,
|
|
|
|
okButtonText, null, null, null, {});
|
2012-12-08 04:13:27 +00:00
|
|
|
if (confirmationIndex == 0) {
|
|
|
|
Social.deactivateFromOrigin(Social.provider.origin);
|
|
|
|
}
|
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;
|
|
|
|
let chromeless = docElem.getAttribute("chromehidden").indexOf("extrachrome") >= 0;
|
|
|
|
// 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;
|
2013-02-07 14:36:31 +00:00
|
|
|
return !!(Social.active && Social.provider && Social.provider.enabled);
|
2013-01-24 10:14:36 +00:00
|
|
|
},
|
|
|
|
|
2012-07-12 01:31:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-21 00:52:26 +00:00
|
|
|
let SocialChatBar = {
|
|
|
|
get chatbar() {
|
|
|
|
return document.getElementById("pinnedchats");
|
|
|
|
},
|
2012-11-13 03:52:06 +00:00
|
|
|
// Whether the chatbar is available for this window. Note that in full-screen
|
|
|
|
// mode chats are available, but not shown.
|
|
|
|
get isAvailable() {
|
2013-01-24 10:14:36 +00:00
|
|
|
return SocialUI.enabled && Social.haveLoggedInUser();
|
2012-08-21 00:52:26 +00:00
|
|
|
},
|
2012-12-06 23:56:17 +00:00
|
|
|
// Does this chatbar have any chats (whether minimized, collapsed or normal)
|
|
|
|
get hasChats() {
|
|
|
|
return !!this.chatbar.firstElementChild;
|
|
|
|
},
|
2012-08-26 23:51:24 +00:00
|
|
|
openChat: function(aProvider, aURL, aCallback, aMode) {
|
2012-11-13 03:52:06 +00:00
|
|
|
if (this.isAvailable)
|
2012-08-26 23:51:24 +00:00
|
|
|
this.chatbar.openChat(aProvider, aURL, aCallback, aMode);
|
2012-08-21 00:52:26 +00:00
|
|
|
},
|
|
|
|
update: function() {
|
2012-11-27 06:58:55 +00:00
|
|
|
let command = document.getElementById("Social:FocusChat");
|
|
|
|
if (!this.isAvailable) {
|
2012-08-21 00:52:26 +00:00
|
|
|
this.chatbar.removeAll();
|
2012-11-27 06:58:55 +00:00
|
|
|
command.hidden = true;
|
|
|
|
} else {
|
|
|
|
this.chatbar.hidden = command.hidden = document.mozFullScreen;
|
2012-11-13 03:52:06 +00:00
|
|
|
}
|
2012-11-27 06:58:55 +00:00
|
|
|
command.setAttribute("disabled", command.hidden ? "true" : "false");
|
2012-10-24 06:45:59 +00:00
|
|
|
},
|
|
|
|
focus: function SocialChatBar_focus() {
|
2012-11-20 01:54:50 +00:00
|
|
|
this.chatbar.focus();
|
2012-08-21 00:52:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 06:14:55 +00:00
|
|
|
function sizeSocialPanelToContent(panel, iframe) {
|
2012-08-24 00:11:02 +00:00
|
|
|
// FIXME: bug 764787: Maybe we can use nsIDOMWindowUtils.getRootBounds() here?
|
|
|
|
let doc = iframe.contentDocument;
|
2012-10-05 03:32:38 +00:00
|
|
|
if (!doc || !doc.body) {
|
2012-08-24 00:11:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-05 03:32:38 +00:00
|
|
|
let body = doc.body;
|
|
|
|
// offsetHeight/Width don't include margins, so account for that.
|
2012-09-26 06:22:38 +00:00
|
|
|
let cs = doc.defaultView.getComputedStyle(body);
|
|
|
|
let computedHeight = parseInt(cs.marginTop) + body.offsetHeight + parseInt(cs.marginBottom);
|
2012-10-05 03:32:38 +00:00
|
|
|
let height = Math.max(computedHeight, PANEL_MIN_HEIGHT);
|
|
|
|
let computedWidth = parseInt(cs.marginLeft) + body.offsetWidth + parseInt(cs.marginRight);
|
|
|
|
let width = Math.max(computedWidth, PANEL_MIN_WIDTH);
|
2012-10-08 06:14:55 +00:00
|
|
|
let wDiff = width - iframe.getBoundingClientRect().width;
|
|
|
|
// A panel resize will move the right margin - if that is where the anchor
|
|
|
|
// arrow is, the arrow will be mis-aligned from the anchor. So we move the
|
|
|
|
// popup to compensate for that. See bug 799014.
|
|
|
|
if (wDiff !== 0 && panel.getAttribute("side") == "right") {
|
|
|
|
let box = panel.boxObject;
|
|
|
|
panel.moveTo(box.screenX - wDiff, box.screenY);
|
|
|
|
}
|
|
|
|
iframe.style.height = height + "px";
|
2012-10-05 03:32:38 +00:00
|
|
|
iframe.style.width = width + "px";
|
2012-08-24 00:11:02 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 03:32:38 +00:00
|
|
|
function DynamicResizeWatcher() {
|
|
|
|
this._mutationObserver = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
DynamicResizeWatcher.prototype = {
|
2012-10-08 06:14:55 +00:00
|
|
|
start: function DynamicResizeWatcher_start(panel, iframe) {
|
2012-10-05 03:32:38 +00:00
|
|
|
this.stop(); // just in case...
|
|
|
|
let doc = iframe.contentDocument;
|
|
|
|
this._mutationObserver = new iframe.contentWindow.MutationObserver(function(mutations) {
|
2012-10-08 06:14:55 +00:00
|
|
|
sizeSocialPanelToContent(panel, iframe);
|
2012-10-05 03:32:38 +00:00
|
|
|
});
|
|
|
|
// Observe anything that causes the size to change.
|
|
|
|
let config = {attributes: true, characterData: true, childList: true, subtree: true};
|
|
|
|
this._mutationObserver.observe(doc, config);
|
|
|
|
// and since this may be setup after the load event has fired we do an
|
|
|
|
// initial resize now.
|
2012-10-08 06:14:55 +00:00
|
|
|
sizeSocialPanelToContent(panel, iframe);
|
2012-10-05 03:32:38 +00:00
|
|
|
},
|
|
|
|
stop: function DynamicResizeWatcher_stop() {
|
|
|
|
if (this._mutationObserver) {
|
|
|
|
try {
|
|
|
|
this._mutationObserver.disconnect();
|
|
|
|
} catch (ex) {
|
|
|
|
// may get "TypeError: can't access dead object" which seems strange,
|
|
|
|
// but doesn't seem to indicate a real problem, so ignore it...
|
|
|
|
}
|
|
|
|
this._mutationObserver = null;
|
2012-09-26 06:22:38 +00:00
|
|
|
}
|
2012-10-05 03:32:38 +00:00
|
|
|
}
|
2012-09-26 06:22:38 +00:00
|
|
|
}
|
|
|
|
|
2012-08-24 00:11:02 +00:00
|
|
|
let SocialFlyout = {
|
|
|
|
get panel() {
|
|
|
|
return document.getElementById("social-flyout-panel");
|
|
|
|
},
|
|
|
|
|
|
|
|
dispatchPanelEvent: function(name) {
|
|
|
|
let doc = this.panel.firstChild.contentDocument;
|
|
|
|
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
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
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");
|
|
|
|
iframe.setAttribute("origin", Social.provider.origin);
|
|
|
|
panel.appendChild(iframe);
|
|
|
|
},
|
|
|
|
|
2012-10-06 00:22:09 +00:00
|
|
|
setFlyoutErrorMessage: function SF_setFlyoutErrorMessage() {
|
|
|
|
let iframe = this.panel.firstChild;
|
|
|
|
if (!iframe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
iframe.removeAttribute("src");
|
|
|
|
iframe.webNavigation.loadURI("about:socialerror?mode=compactInfo", null, null, null, null);
|
2012-11-28 01:50:03 +00:00
|
|
|
sizeSocialPanelToContent(this.panel, iframe);
|
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;
|
|
|
|
if (iframe.socialErrorListener)
|
|
|
|
iframe.socialErrorListener.remove();
|
|
|
|
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;
|
|
|
|
let iframe = panel.firstChild;
|
2012-10-05 03:32:38 +00:00
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
2012-08-24 00:11:02 +00:00
|
|
|
iframe.docShell.isActive = true;
|
|
|
|
iframe.docShell.isAppTab = true;
|
|
|
|
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;
|
2012-08-24 00:11:02 +00:00
|
|
|
this.panel.firstChild.docShell.isActive = false;
|
|
|
|
this.dispatchPanelEvent("socialFrameHide");
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (!panel.firstChild)
|
|
|
|
this._createFrame();
|
|
|
|
panel.hidden = false;
|
|
|
|
let iframe = panel.firstChild;
|
|
|
|
|
|
|
|
let src = iframe.getAttribute("src");
|
|
|
|
if (src != aURL) {
|
|
|
|
iframe.addEventListener("load", function documentLoaded() {
|
|
|
|
iframe.removeEventListener("load", documentLoaded, true);
|
|
|
|
if (aCallback) {
|
|
|
|
try {
|
|
|
|
aCallback(iframe.contentWindow);
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
iframe.setAttribute("src", aURL);
|
|
|
|
}
|
|
|
|
else if (aCallback) {
|
|
|
|
try {
|
|
|
|
aCallback(iframe.contentWindow);
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 06:14:55 +00:00
|
|
|
sizeSocialPanelToContent(panel, iframe);
|
2012-08-24 00:11:02 +00:00
|
|
|
let anchor = document.getElementById("social-sidebar-browser");
|
2012-09-21 05:18:48 +00:00
|
|
|
if (panel.state == "open") {
|
|
|
|
// this is painful - there is no way to say "move to a new anchor offset",
|
|
|
|
// only "move to new screen pos". So we remember the last yOffset,
|
|
|
|
// calculate the adjustment needed to the new yOffset, then calc the
|
|
|
|
// screen Y position.
|
|
|
|
let yAdjust = yOffset - this.yOffset;
|
|
|
|
let box = panel.boxObject;
|
|
|
|
panel.moveTo(box.screenX, box.screenY + yAdjust);
|
|
|
|
} else {
|
|
|
|
panel.openPopup(anchor, "start_before", 0, yOffset, false, false);
|
2013-01-26 20:07:39 +00:00
|
|
|
// Force a layout flush by calling .clientTop so
|
|
|
|
// that the docShell of this frame is created
|
|
|
|
panel.firstChild.clientTop;
|
|
|
|
Social.setErrorListener(iframe, this.setFlyoutErrorMessage.bind(this))
|
2012-09-21 05:18:48 +00:00
|
|
|
}
|
|
|
|
this.yOffset = yOffset;
|
2012-08-24 00:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-12 01:31:19 +00:00
|
|
|
let SocialShareButton = {
|
2012-07-18 18:40:05 +00:00
|
|
|
// Called once, after window load, when the Social.provider object is initialized
|
2012-07-12 01:31:19 +00:00
|
|
|
init: function SSB_init() {
|
2012-12-08 04:13:27 +00:00
|
|
|
this.updateProvider();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called when the Social.provider changes
|
|
|
|
updateProvider: function () {
|
2012-07-15 23:12:13 +00:00
|
|
|
this.updateButtonHiddenState();
|
2012-12-08 04:13:27 +00:00
|
|
|
if (!Social.provider)
|
|
|
|
return;
|
2012-07-25 17:35:57 +00:00
|
|
|
this.updateProfileInfo();
|
|
|
|
},
|
2012-07-17 17:47:04 +00:00
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// Called when the provider's profile info changes (or when the provider
|
|
|
|
// changes, via updateProvider)
|
2012-07-25 17:35:57 +00:00
|
|
|
updateProfileInfo: function SSB_updateProfileInfo() {
|
2012-09-25 03:54:34 +00:00
|
|
|
let profileRow = document.getElementById("unsharePopupHeader");
|
2013-01-24 10:14:36 +00:00
|
|
|
let profile = SocialUI.enabled ? Social.provider.profile : null;
|
2012-08-02 22:30:19 +00:00
|
|
|
if (profile && profile.displayName) {
|
2012-07-17 17:47:04 +00:00
|
|
|
profileRow.hidden = false;
|
|
|
|
let portrait = document.getElementById("socialUserPortrait");
|
2012-09-25 18:39:09 +00:00
|
|
|
portrait.setAttribute("src", profile.portrait || "chrome://global/skin/icons/information-32.png");
|
2012-07-17 17:47:04 +00:00
|
|
|
let displayName = document.getElementById("socialUserDisplayName");
|
|
|
|
displayName.setAttribute("label", profile.displayName);
|
|
|
|
} else {
|
|
|
|
profileRow.hidden = true;
|
2012-09-06 20:47:01 +00:00
|
|
|
this.updateButtonHiddenState();
|
2012-07-17 17:47:04 +00:00
|
|
|
}
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get shareButton() {
|
|
|
|
return document.getElementById("share-button");
|
|
|
|
},
|
2012-09-25 03:54:34 +00:00
|
|
|
get unsharePopup() {
|
|
|
|
return document.getElementById("unsharePopup");
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
2012-09-25 03:54:34 +00:00
|
|
|
dismissUnsharePopup: function SSB_dismissUnsharePopup() {
|
|
|
|
this.unsharePopup.hidePopup();
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
2012-10-25 05:44:53 +00:00
|
|
|
canSharePage: function SSB_canSharePage(aURI) {
|
|
|
|
// We only allow sharing of http or https
|
|
|
|
return aURI && (aURI.schemeIs('http') || aURI.schemeIs('https'));
|
|
|
|
},
|
|
|
|
|
2012-07-15 23:12:13 +00:00
|
|
|
updateButtonHiddenState: function SSB_updateButtonHiddenState() {
|
2012-07-12 01:31:19 +00:00
|
|
|
let shareButton = this.shareButton;
|
|
|
|
if (shareButton)
|
2013-01-24 10:14:36 +00:00
|
|
|
shareButton.hidden = !SocialUI.enabled || Social.provider.recommendInfo == null ||
|
2012-12-08 04:13:27 +00:00
|
|
|
!Social.haveLoggedInUser() ||
|
2012-10-25 05:44:53 +00:00
|
|
|
!this.canSharePage(gBrowser.currentURI);
|
2012-12-08 04:13:27 +00:00
|
|
|
|
2012-11-27 06:59:51 +00:00
|
|
|
// also update the relevent command's disabled state so the keyboard
|
|
|
|
// shortcut only works when available.
|
|
|
|
let cmd = document.getElementById("Social:SharePage");
|
|
|
|
cmd.setAttribute("disabled", shareButton.hidden ? "true" : "false");
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function SSB_onClick(aEvent) {
|
|
|
|
if (aEvent.button != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't bubble to the textbox, to avoid unwanted selection of the address.
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
|
|
|
|
this.sharePage();
|
|
|
|
},
|
|
|
|
|
|
|
|
panelShown: function SSB_panelShown(aEvent) {
|
2012-09-25 03:54:34 +00:00
|
|
|
function updateElement(id, attrs) {
|
|
|
|
let el = document.getElementById(id);
|
|
|
|
Object.keys(attrs).forEach(function(attr) {
|
|
|
|
el.setAttribute(attr, attrs[attr]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
let continueSharingButton = document.getElementById("unsharePopupContinueSharingButton");
|
|
|
|
continueSharingButton.focus();
|
2012-11-15 03:57:28 +00:00
|
|
|
let recommendInfo = Social.provider.recommendInfo;
|
2012-09-25 03:54:34 +00:00
|
|
|
updateElement("unsharePopupContinueSharingButton",
|
2012-11-15 03:57:28 +00:00
|
|
|
{label: recommendInfo.messages.unshareCancelLabel,
|
|
|
|
accesskey: recommendInfo.messages.unshareCancelAccessKey});
|
2012-09-25 03:54:34 +00:00
|
|
|
updateElement("unsharePopupStopSharingButton",
|
2012-11-15 03:57:28 +00:00
|
|
|
{label: recommendInfo.messages.unshareConfirmLabel,
|
|
|
|
accesskey: recommendInfo.messages.unshareConfirmAccessKey});
|
2012-09-25 03:54:34 +00:00
|
|
|
updateElement("socialUserPortrait",
|
2012-11-15 03:57:28 +00:00
|
|
|
{"aria-label": recommendInfo.messages.portraitLabel});
|
2012-09-25 03:54:34 +00:00
|
|
|
updateElement("socialUserRecommendedText",
|
2012-11-15 03:57:28 +00:00
|
|
|
{value: recommendInfo.messages.unshareLabel});
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sharePage: function SSB_sharePage() {
|
2012-09-25 03:54:34 +00:00
|
|
|
this.unsharePopup.hidden = false;
|
2012-07-18 18:40:05 +00:00
|
|
|
|
2012-07-12 01:31:19 +00:00
|
|
|
let uri = gBrowser.currentURI;
|
|
|
|
if (!Social.isPageShared(uri)) {
|
|
|
|
Social.sharePage(uri);
|
|
|
|
this.updateShareState();
|
|
|
|
} else {
|
2012-09-25 03:54:34 +00:00
|
|
|
this.unsharePopup.openPopup(this.shareButton, "bottomcenter topright");
|
2012-07-12 01:31:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
unsharePage: function SSB_unsharePage() {
|
|
|
|
Social.unsharePage(gBrowser.currentURI);
|
|
|
|
this.updateShareState();
|
2012-09-25 03:54:34 +00:00
|
|
|
this.dismissUnsharePopup();
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateShareState: function SSB_updateShareState() {
|
2012-10-25 05:44:53 +00:00
|
|
|
this.updateButtonHiddenState();
|
|
|
|
|
|
|
|
let shareButton = this.shareButton;
|
|
|
|
let currentPageShared = shareButton && !shareButton.hidden && Social.isPageShared(gBrowser.currentURI);
|
2012-07-12 01:31:19 +00:00
|
|
|
|
2013-01-24 10:14:36 +00:00
|
|
|
let recommendInfo = SocialUI.enabled ? Social.provider.recommendInfo : null;
|
2012-07-12 01:31:19 +00:00
|
|
|
// Provide a11y-friendly notification of share.
|
|
|
|
let status = document.getElementById("share-button-status");
|
|
|
|
if (status) {
|
2012-08-27 11:16:38 +00:00
|
|
|
// XXX - this should also be capable of reflecting that the page was
|
|
|
|
// unshared (ie, it needs to manage three-states: (1) nothing done, (2)
|
|
|
|
// shared, (3) shared then unshared)
|
|
|
|
// Note that we *do* have an appropriate string from the provider for
|
2012-11-15 03:57:28 +00:00
|
|
|
// this (recommendInfo.messages.unsharedLabel) but currently lack a way of
|
2012-08-27 11:16:38 +00:00
|
|
|
// tracking this state)
|
2012-11-15 03:57:28 +00:00
|
|
|
let statusString = currentPageShared && recommendInfo ?
|
|
|
|
recommendInfo.messages.sharedLabel : "";
|
2012-07-12 01:31:19 +00:00
|
|
|
status.setAttribute("value", statusString);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the share button, if present
|
2012-08-27 11:16:38 +00:00
|
|
|
if (!shareButton || shareButton.hidden)
|
2012-07-12 01:31:19 +00:00
|
|
|
return;
|
|
|
|
|
2012-08-27 11:16:38 +00:00
|
|
|
let imageURL;
|
2012-07-12 01:31:19 +00:00
|
|
|
if (currentPageShared) {
|
|
|
|
shareButton.setAttribute("shared", "true");
|
2012-11-15 03:57:28 +00:00
|
|
|
shareButton.setAttribute("tooltiptext", recommendInfo.messages.unshareTooltip);
|
|
|
|
imageURL = recommendInfo.images.unshare;
|
2012-07-12 01:31:19 +00:00
|
|
|
} else {
|
|
|
|
shareButton.removeAttribute("shared");
|
2012-11-15 03:57:28 +00:00
|
|
|
shareButton.setAttribute("tooltiptext", recommendInfo.messages.shareTooltip);
|
|
|
|
imageURL = recommendInfo.images.share;
|
2012-07-12 01:31:19 +00:00
|
|
|
}
|
2012-10-24 02:46:05 +00:00
|
|
|
shareButton.src = imageURL;
|
2012-07-12 01:31:19 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-15 23:12:13 +00:00
|
|
|
|
2012-10-12 01:21:50 +00:00
|
|
|
var SocialMenu = {
|
|
|
|
populate: function SocialMenu_populate() {
|
2012-11-15 23:07:42 +00:00
|
|
|
let submenu = document.getElementById("menu_social-statusarea-popup");
|
2012-10-22 00:25:19 +00:00
|
|
|
let ambientMenuItems = submenu.getElementsByClassName("ambient-menuitem");
|
2012-11-09 23:36:22 +00:00
|
|
|
while (ambientMenuItems.length)
|
|
|
|
submenu.removeChild(ambientMenuItems.item(0));
|
2012-10-25 19:30:59 +00:00
|
|
|
|
|
|
|
let separator = document.getElementById("socialAmbientMenuSeparator");
|
|
|
|
separator.hidden = true;
|
2013-01-24 10:14:36 +00:00
|
|
|
let provider = SocialUI.enabled ? Social.provider : null;
|
|
|
|
if (!provider)
|
2012-12-08 04:13:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
let iconNames = Object.keys(provider.ambientNotificationIcons);
|
|
|
|
for (let name of iconNames) {
|
|
|
|
let icon = provider.ambientNotificationIcons[name];
|
|
|
|
if (!icon.label || !icon.menuURL)
|
|
|
|
continue;
|
|
|
|
separator.hidden = false;
|
|
|
|
let menuitem = document.createElement("menuitem");
|
|
|
|
menuitem.setAttribute("label", icon.label);
|
|
|
|
menuitem.classList.add("ambient-menuitem");
|
|
|
|
menuitem.addEventListener("command", function() {
|
|
|
|
openUILinkIn(icon.menuURL, "tab");
|
|
|
|
}, false);
|
|
|
|
submenu.insertBefore(menuitem, separator);
|
2012-10-12 01:21:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// XXX Need to audit that this is being initialized correctly
|
2012-07-15 23:12:13 +00:00
|
|
|
var SocialToolbar = {
|
2012-12-08 04:13:27 +00:00
|
|
|
// Called once, after window load, when the Social.provider object is
|
|
|
|
// initialized.
|
2012-07-15 23:12:13 +00:00
|
|
|
init: function SocialToolbar_init() {
|
2013-02-05 05:42:18 +00:00
|
|
|
let accesskey = gNavigatorBundle.getString("social.removeProvider.accesskey");
|
2012-11-15 23:07:42 +00:00
|
|
|
let removeCommand = document.getElementById("Social:Remove");
|
|
|
|
removeCommand.setAttribute("accesskey", accesskey);
|
2012-10-30 06:25:53 +00:00
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
this.updateProvider();
|
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called when the Social.provider changes
|
|
|
|
updateProvider: function () {
|
2013-02-07 14:36:31 +00:00
|
|
|
if (Social.provider) {
|
2013-02-05 05:42:18 +00:00
|
|
|
let label = gNavigatorBundle.getFormattedString("social.removeProvider.label",
|
2013-02-07 14:36:31 +00:00
|
|
|
[Social.provider.name]);
|
2013-02-05 05:42:18 +00:00
|
|
|
let removeCommand = document.getElementById("Social:Remove");
|
|
|
|
removeCommand.setAttribute("label", label);
|
2013-02-07 14:36:31 +00:00
|
|
|
this.button.setAttribute("label", Social.provider.name);
|
|
|
|
this.button.setAttribute("tooltiptext", Social.provider.name);
|
|
|
|
this.button.style.listStyleImage = "url(" + Social.provider.iconURL + ")";
|
2013-02-05 05:42:18 +00:00
|
|
|
|
|
|
|
this.updateProfile();
|
|
|
|
}
|
2012-07-15 23:12:13 +00:00
|
|
|
this.updateButton();
|
2012-12-08 04:13:27 +00:00
|
|
|
this.populateProviderMenus();
|
2012-07-15 23:12:13 +00:00
|
|
|
},
|
|
|
|
|
2012-10-04 04:00:57 +00:00
|
|
|
get button() {
|
|
|
|
return document.getElementById("social-provider-button");
|
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// Note: this doesn't actually handle hiding the toolbar button,
|
|
|
|
// socialActiveBroadcaster is responsible for that.
|
2012-07-15 23:12:13 +00:00
|
|
|
updateButtonHiddenState: function SocialToolbar_updateButtonHiddenState() {
|
2012-09-27 23:57:37 +00:00
|
|
|
let tbi = document.getElementById("social-toolbar-item");
|
2013-01-24 10:14:36 +00:00
|
|
|
let socialEnabled = SocialUI.enabled;
|
2012-11-15 23:07:42 +00:00
|
|
|
for (let className of ["social-statusarea-separator", "social-statusarea-user"]) {
|
|
|
|
for (let element of document.getElementsByClassName(className))
|
|
|
|
element.hidden = !socialEnabled;
|
|
|
|
}
|
|
|
|
let toggleNotificationsCommand = document.getElementById("Social:ToggleNotifications");
|
|
|
|
toggleNotificationsCommand.setAttribute("hidden", !socialEnabled);
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
if (!Social.haveLoggedInUser() || !socialEnabled) {
|
2012-10-16 06:58:13 +00:00
|
|
|
let parent = document.getElementById("social-notification-panel");
|
2012-12-07 07:38:46 +00:00
|
|
|
while (parent.hasChildNodes()) {
|
|
|
|
let frame = parent.firstChild;
|
|
|
|
SharedFrame.forgetGroup(frame.id);
|
|
|
|
parent.removeChild(frame);
|
|
|
|
}
|
2012-09-27 23:57:37 +00:00
|
|
|
|
|
|
|
while (tbi.lastChild != tbi.firstChild)
|
|
|
|
tbi.removeChild(tbi.lastChild);
|
2012-08-17 01:02:23 +00:00
|
|
|
}
|
2012-07-15 23:12:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateProfile: function SocialToolbar_updateProfile() {
|
|
|
|
// Profile may not have been initialized yet, since it depends on a worker
|
|
|
|
// response. In that case we'll be called again when it's available, via
|
|
|
|
// social:profile-changed
|
|
|
|
let profile = Social.provider.profile || {};
|
2012-09-25 18:39:09 +00:00
|
|
|
let userPortrait = profile.portrait || "chrome://global/skin/icons/information-32.png";
|
2012-11-15 23:07:42 +00:00
|
|
|
|
2012-11-20 01:22:42 +00:00
|
|
|
let userDetailsBroadcaster = document.getElementById("socialBroadcaster_userDetails");
|
2012-12-08 04:13:27 +00:00
|
|
|
let loggedInStatusValue = profile.userName ||
|
|
|
|
userDetailsBroadcaster.getAttribute("notLoggedInLabel");
|
2012-11-20 01:22:42 +00:00
|
|
|
|
|
|
|
// "image" and "label" are used by Mac's native menus that do not render the menuitem's children
|
|
|
|
// elements. "src" and "value" are used by the image/label children on the other platforms.
|
|
|
|
userDetailsBroadcaster.setAttribute("src", userPortrait);
|
|
|
|
userDetailsBroadcaster.setAttribute("image", userPortrait);
|
|
|
|
|
|
|
|
userDetailsBroadcaster.setAttribute("value", loggedInStatusValue);
|
|
|
|
userDetailsBroadcaster.setAttribute("label", loggedInStatusValue);
|
2012-07-15 23:12:13 +00:00
|
|
|
},
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// XXX doesn't this need to be called for profile changes, given its use of provider.profile?
|
2012-07-15 23:12:13 +00:00
|
|
|
updateButton: function SocialToolbar_updateButton() {
|
|
|
|
this.updateButtonHiddenState();
|
2013-02-07 14:36:31 +00:00
|
|
|
let provider = Social.provider;
|
2012-08-23 18:23:17 +00:00
|
|
|
let panel = document.getElementById("social-notification-panel");
|
2013-02-05 05:42:18 +00:00
|
|
|
panel.hidden = !SocialUI.enabled;
|
2012-10-08 00:15:02 +00:00
|
|
|
|
|
|
|
let command = document.getElementById("Social:ToggleNotifications");
|
|
|
|
command.setAttribute("checked", Services.prefs.getBoolPref("social.toast-notifications.enabled"));
|
|
|
|
|
2012-11-29 06:14:48 +00:00
|
|
|
const CACHE_PREF_NAME = "social.cached.ambientNotificationIcons";
|
2012-10-08 00:15:02 +00:00
|
|
|
// provider.profile == undefined means no response yet from the provider
|
|
|
|
// to tell us whether the user is logged in or not.
|
2013-01-24 10:14:36 +00:00
|
|
|
if (!SocialUI.enabled ||
|
2013-02-07 14:36:31 +00:00
|
|
|
(!Social.haveLoggedInUser() && provider.profile !== undefined)) {
|
2012-10-23 07:47:29 +00:00
|
|
|
// Either no enabled provider, or there is a provider and it has
|
|
|
|
// responded with a profile and the user isn't loggedin. The icons
|
|
|
|
// etc have already been removed by updateButtonHiddenState, so we want
|
|
|
|
// to nuke any cached icons we have and get out of here!
|
2012-10-08 00:15:02 +00:00
|
|
|
Services.prefs.clearUserPref(CACHE_PREF_NAME);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-07 14:36:31 +00:00
|
|
|
let icons = provider.ambientNotificationIcons;
|
2013-02-05 05:42:18 +00:00
|
|
|
let iconNames = Object.keys(icons);
|
2012-10-08 00:15:02 +00:00
|
|
|
if (Social.provider.profile === undefined) {
|
|
|
|
// provider has not told us about the login state yet - see if we have
|
|
|
|
// a cached version for this provider.
|
|
|
|
let cached;
|
|
|
|
try {
|
2012-11-29 06:14:48 +00:00
|
|
|
cached = JSON.parse(Services.prefs.getComplexValue(CACHE_PREF_NAME,
|
|
|
|
Ci.nsISupportsString).data);
|
2012-10-08 00:15:02 +00:00
|
|
|
} catch (ex) {}
|
|
|
|
if (cached && cached.provider == Social.provider.origin && cached.data) {
|
|
|
|
icons = cached.data;
|
|
|
|
iconNames = Object.keys(icons);
|
|
|
|
// delete the counter data as it is almost certainly stale.
|
|
|
|
for each(let name in iconNames) {
|
|
|
|
icons[name].counter = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We have a logged in user - save the current set of icons back to the
|
|
|
|
// "cache" so we can use them next startup.
|
2012-11-29 06:14:48 +00:00
|
|
|
let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
|
|
str.data = JSON.stringify({provider: Social.provider.origin, data: icons});
|
|
|
|
Services.prefs.setComplexValue(CACHE_PREF_NAME,
|
|
|
|
Ci.nsISupportsString,
|
|
|
|
str);
|
2012-10-08 00:15:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 20:42:02 +00:00
|
|
|
let toolbarButtons = document.createDocumentFragment();
|
2012-08-17 01:02:23 +00:00
|
|
|
|
2012-10-06 00:22:09 +00:00
|
|
|
let createdFrames = [];
|
|
|
|
|
2012-08-17 01:02:23 +00:00
|
|
|
for each(let name in iconNames) {
|
2012-10-08 00:15:02 +00:00
|
|
|
let icon = icons[name];
|
2012-08-17 01:02:23 +00:00
|
|
|
|
2012-08-22 20:56:14 +00:00
|
|
|
let notificationFrameId = "social-status-" + icon.name;
|
|
|
|
let notificationFrame = document.getElementById(notificationFrameId);
|
2012-12-07 07:38:46 +00:00
|
|
|
|
2012-08-22 20:56:14 +00:00
|
|
|
if (!notificationFrame) {
|
2012-12-07 07:38:46 +00:00
|
|
|
notificationFrame = SharedFrame.createFrame(
|
|
|
|
notificationFrameId, /* frame name */
|
|
|
|
panel, /* parent */
|
|
|
|
{
|
|
|
|
"type": "content",
|
|
|
|
"mozbrowser": "true",
|
|
|
|
"class": "social-panel-frame",
|
|
|
|
"id": notificationFrameId,
|
|
|
|
|
|
|
|
// work around bug 793057 - by making the panel roughly the final size
|
|
|
|
// we are more likely to have the anchor in the correct position.
|
|
|
|
"style": "width: " + PANEL_MIN_WIDTH + "px;",
|
|
|
|
|
2013-02-07 14:36:31 +00:00
|
|
|
"origin": provider.origin,
|
2012-12-07 07:38:46 +00:00
|
|
|
"src": icon.contentPanel
|
|
|
|
}
|
|
|
|
);
|
2012-10-06 00:22:09 +00:00
|
|
|
|
|
|
|
createdFrames.push(notificationFrame);
|
2012-12-07 07:38:46 +00:00
|
|
|
} else {
|
2013-02-07 14:36:31 +00:00
|
|
|
notificationFrame.setAttribute("origin", provider.origin);
|
2012-12-07 07:38:46 +00:00
|
|
|
SharedFrame.updateURL(notificationFrameId, icon.contentPanel);
|
2012-07-15 23:12:13 +00:00
|
|
|
}
|
2012-08-17 01:02:23 +00:00
|
|
|
|
2013-01-07 20:42:02 +00:00
|
|
|
let toolbarButtonContainerId = "social-notification-container-" + icon.name;
|
|
|
|
let toolbarButtonId = "social-notification-icon-" + icon.name;
|
|
|
|
let toolbarButtonContainer = document.getElementById(toolbarButtonContainerId);
|
|
|
|
let toolbarButton = document.getElementById(toolbarButtonId);
|
|
|
|
if (!toolbarButtonContainer) {
|
|
|
|
// The container is used to fix an issue with position:absolute on
|
|
|
|
// generated content not being constrained to the bounding box of a
|
|
|
|
// parent toolbarbutton that has position:relative.
|
|
|
|
toolbarButtonContainer = document.createElement("toolbaritem");
|
|
|
|
toolbarButtonContainer.classList.add("social-notification-container");
|
|
|
|
toolbarButtonContainer.setAttribute("id", toolbarButtonContainerId);
|
|
|
|
|
|
|
|
toolbarButton = document.createElement("toolbarbutton");
|
|
|
|
toolbarButton.classList.add("toolbarbutton-1");
|
|
|
|
toolbarButton.setAttribute("id", toolbarButtonId);
|
|
|
|
toolbarButton.setAttribute("notificationFrameId", notificationFrameId);
|
|
|
|
toolbarButton.addEventListener("mousedown", function (event) {
|
2013-02-08 16:34:46 +00:00
|
|
|
if (event.button == 0 && panel.state == "closed")
|
2013-01-07 20:42:02 +00:00
|
|
|
SocialToolbar.showAmbientPopup(toolbarButton);
|
|
|
|
});
|
|
|
|
|
|
|
|
toolbarButtonContainer.appendChild(toolbarButton);
|
|
|
|
toolbarButtons.appendChild(toolbarButtonContainer);
|
2012-09-29 10:17:29 +00:00
|
|
|
}
|
2012-09-27 23:57:37 +00:00
|
|
|
|
2013-01-07 20:42:02 +00:00
|
|
|
toolbarButton.style.listStyleImage = "url(" + icon.iconURL + ")";
|
|
|
|
toolbarButton.setAttribute("label", icon.label);
|
|
|
|
toolbarButton.setAttribute("tooltiptext", icon.label);
|
2012-09-27 23:57:37 +00:00
|
|
|
|
2013-01-07 20:42:02 +00:00
|
|
|
let badge = icon.counter || "";
|
2013-02-07 23:59:10 +00:00
|
|
|
toolbarButton.setAttribute("badge", badge);
|
|
|
|
let ariaLabel = icon.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]);
|
|
|
|
toolbarButton.setAttribute("aria-label", ariaLabel);
|
2012-08-17 01:02:23 +00:00
|
|
|
}
|
2013-01-07 20:42:02 +00:00
|
|
|
let socialToolbarItem = document.getElementById("social-toolbar-item");
|
|
|
|
socialToolbarItem.appendChild(toolbarButtons);
|
2012-10-06 00:22:09 +00:00
|
|
|
|
|
|
|
for (let frame of createdFrames) {
|
2013-01-26 20:07:39 +00:00
|
|
|
if (frame.socialErrorListener) {
|
|
|
|
frame.socialErrorListener.remove();
|
|
|
|
}
|
2012-10-06 00:22:09 +00:00
|
|
|
if (frame.docShell) {
|
2012-10-06 00:22:09 +00:00
|
|
|
frame.docShell.isActive = false;
|
2013-01-26 20:07:39 +00:00
|
|
|
Social.setErrorListener(frame, this.setPanelErrorMessage.bind(this));
|
2012-10-06 00:22:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-15 23:12:13 +00:00
|
|
|
},
|
|
|
|
|
2013-01-07 20:42:02 +00:00
|
|
|
showAmbientPopup: function SocialToolbar_showAmbientPopup(aToolbarButton) {
|
2012-10-22 00:28:37 +00:00
|
|
|
// Hide any other social panels that may be open.
|
|
|
|
SocialFlyout.panel.hidePopup();
|
|
|
|
|
2012-07-15 23:12:13 +00:00
|
|
|
let panel = document.getElementById("social-notification-panel");
|
2013-01-07 20:42:02 +00:00
|
|
|
let notificationFrameId = aToolbarButton.getAttribute("notificationFrameId");
|
2012-09-27 23:57:37 +00:00
|
|
|
let notificationFrame = document.getElementById(notificationFrameId);
|
2012-07-15 23:12:13 +00:00
|
|
|
|
2012-12-07 07:38:46 +00:00
|
|
|
let wasAlive = SharedFrame.isGroupAlive(notificationFrameId);
|
|
|
|
SharedFrame.setOwner(notificationFrameId, notificationFrame);
|
|
|
|
|
2012-08-24 00:11:02 +00:00
|
|
|
// Clear dimensions on all browsers so the panel size will
|
|
|
|
// only use the selected browser.
|
2012-10-16 06:58:13 +00:00
|
|
|
let frameIter = panel.firstElementChild;
|
2012-08-24 00:11:02 +00:00
|
|
|
while (frameIter) {
|
|
|
|
frameIter.collapsed = (frameIter != notificationFrame);
|
|
|
|
frameIter = frameIter.nextElementSibling;
|
2012-07-15 23:12:13 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 18:25:47 +00:00
|
|
|
function dispatchPanelEvent(name) {
|
2012-08-22 20:56:14 +00:00
|
|
|
let evt = notificationFrame.contentDocument.createEvent("CustomEvent");
|
2012-08-20 18:25:47 +00:00
|
|
|
evt.initCustomEvent(name, true, true, {});
|
2012-08-22 20:56:14 +00:00
|
|
|
notificationFrame.contentDocument.documentElement.dispatchEvent(evt);
|
2012-08-20 18:25:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 03:32:38 +00:00
|
|
|
let dynamicResizer = this._dynamicResizer;
|
2012-08-24 00:10:07 +00:00
|
|
|
panel.addEventListener("popuphidden", function onpopuphiding() {
|
|
|
|
panel.removeEventListener("popuphidden", onpopuphiding);
|
2013-01-07 20:42:02 +00:00
|
|
|
aToolbarButton.removeAttribute("open");
|
|
|
|
aToolbarButton.parentNode.removeAttribute("open");
|
2012-10-05 03:32:38 +00:00
|
|
|
dynamicResizer.stop();
|
2012-08-24 00:10:07 +00:00
|
|
|
notificationFrame.docShell.isActive = false;
|
2012-08-20 18:25:47 +00:00
|
|
|
dispatchPanelEvent("socialFrameHide");
|
|
|
|
});
|
|
|
|
|
|
|
|
panel.addEventListener("popupshown", function onpopupshown() {
|
|
|
|
panel.removeEventListener("popupshown", onpopupshown);
|
2013-01-07 20:42:02 +00:00
|
|
|
// This attribute is needed on both the button and the
|
|
|
|
// containing toolbaritem since the buttons on OS X have
|
|
|
|
// moz-appearance:none, while their container gets
|
|
|
|
// moz-appearance:toolbarbutton due to the way that toolbar buttons
|
|
|
|
// get combined on OS X.
|
|
|
|
aToolbarButton.setAttribute("open", "true");
|
|
|
|
aToolbarButton.parentNode.setAttribute("open", "true");
|
2012-08-24 00:10:07 +00:00
|
|
|
notificationFrame.docShell.isActive = true;
|
2012-08-22 20:56:14 +00:00
|
|
|
notificationFrame.docShell.isAppTab = true;
|
2012-12-07 07:38:46 +00:00
|
|
|
if (notificationFrame.contentDocument.readyState == "complete" && wasAlive) {
|
2012-10-08 06:14:55 +00:00
|
|
|
dynamicResizer.start(panel, notificationFrame);
|
2012-08-20 18:25:47 +00:00
|
|
|
dispatchPanelEvent("socialFrameShow");
|
|
|
|
} else {
|
|
|
|
// first time load, wait for load and dispatch after load
|
2012-08-22 20:56:14 +00:00
|
|
|
notificationFrame.addEventListener("load", function panelBrowserOnload(e) {
|
|
|
|
notificationFrame.removeEventListener("load", panelBrowserOnload, true);
|
2012-10-08 06:14:55 +00:00
|
|
|
dynamicResizer.start(panel, notificationFrame);
|
2012-08-20 18:25:47 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
dispatchPanelEvent("socialFrameShow");
|
|
|
|
}, 0);
|
|
|
|
}, true);
|
|
|
|
}
|
2012-07-15 23:12:13 +00:00
|
|
|
});
|
|
|
|
|
2013-01-16 19:07:45 +00:00
|
|
|
let navBar = document.getElementById("nav-bar");
|
|
|
|
let anchor = navBar.getAttribute("mode") == "text" ?
|
|
|
|
document.getAnonymousElementByAttribute(aToolbarButton, "class", "toolbarbutton-text") :
|
|
|
|
document.getAnonymousElementByAttribute(aToolbarButton, "class", "toolbarbutton-icon");
|
|
|
|
panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
|
2012-10-06 00:22:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setPanelErrorMessage: function SocialToolbar_setPanelErrorMessage(aNotificationFrame) {
|
|
|
|
if (!aNotificationFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let src = aNotificationFrame.getAttribute("src");
|
|
|
|
aNotificationFrame.removeAttribute("src");
|
|
|
|
aNotificationFrame.webNavigation.loadURI("about:socialerror?mode=tryAgainOnly&url=" +
|
|
|
|
encodeURIComponent(src), null, null, null, null);
|
2012-11-28 01:50:03 +00:00
|
|
|
let panel = aNotificationFrame.parentNode;
|
|
|
|
sizeSocialPanelToContent(panel, aNotificationFrame);
|
2012-12-08 04:13:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
populateProviderMenus: function SocialToolbar_renderProviderMenus() {
|
|
|
|
let providerMenuSeps = document.getElementsByClassName("social-provider-menu");
|
2013-02-07 14:36:31 +00:00
|
|
|
let activeProviders = [p for (p of Social.providers) if (p.active)];
|
2012-12-08 04:13:27 +00:00
|
|
|
for (let providerMenuSep of providerMenuSeps)
|
2013-02-07 14:36:31 +00:00
|
|
|
this._populateProviderMenu(providerMenuSep, activeProviders);
|
2012-12-08 04:13:27 +00:00
|
|
|
},
|
|
|
|
|
2013-02-07 14:36:31 +00:00
|
|
|
_populateProviderMenu: function SocialToolbar_renderProviderMenu(providerMenuSep, providers) {
|
2012-12-08 04:13:27 +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);
|
|
|
|
}
|
2013-01-24 10:14:36 +00:00
|
|
|
// only show a selection if enabled and there is more than one
|
2013-02-07 14:36:31 +00:00
|
|
|
if (!SocialUI.enabled || providers.length < 2) {
|
2012-12-08 04:13:27 +00:00
|
|
|
providerMenuSep.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
2013-02-07 14:36:31 +00:00
|
|
|
for (let provider of providers) {
|
2012-12-08 04:13:27 +00:00
|
|
|
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 (provider == Social.provider) {
|
|
|
|
menuitem.setAttribute("checked", "true");
|
|
|
|
} else {
|
|
|
|
menuitem.setAttribute("oncommand", "Social.setProviderByOrigin(this.getAttribute('origin'));");
|
|
|
|
}
|
|
|
|
menu.insertBefore(menuitem, providerMenuSep);
|
|
|
|
}
|
|
|
|
providerMenuSep.hidden = false;
|
2012-07-15 23:12:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-18 18:40:05 +00:00
|
|
|
|
|
|
|
var SocialSidebar = {
|
|
|
|
// Called once, after window load, when the Social.provider object is initialized
|
|
|
|
init: function SocialSidebar_init() {
|
2012-10-30 03:52:56 +00:00
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
2013-01-26 20:07:39 +00:00
|
|
|
Social.setErrorListener(sbrowser, this.setSidebarErrorMessage.bind(this));
|
2012-10-30 03:52:56 +00:00
|
|
|
// setting isAppTab causes clicks on untargeted links to open new tabs
|
2013-01-26 20:07:39 +00:00
|
|
|
sbrowser.docShell.isAppTab = true;
|
|
|
|
this.update();
|
2012-10-30 03:52:56 +00:00
|
|
|
},
|
|
|
|
|
2012-07-18 18:40:05 +00:00
|
|
|
// Whether the sidebar can be shown for this window.
|
|
|
|
get canShow() {
|
2013-01-24 10:14:36 +00:00
|
|
|
return SocialUI.enabled && Social.provider.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() {
|
|
|
|
return Services.prefs.getBoolPref("social.sidebar.open") && !document.mozFullScreen;
|
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);
|
|
|
|
},
|
|
|
|
|
2012-11-13 03:52:06 +00:00
|
|
|
update: function SocialSidebar_update() {
|
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 {
|
2012-12-14 04:42:37 +00:00
|
|
|
sbrowser.setAttribute("origin", Social.provider.origin);
|
2012-12-08 04:13:27 +00:00
|
|
|
if (Social.provider.errorState == "frameworker-error") {
|
2013-01-26 20:07:39 +00:00
|
|
|
SocialSidebar.setSidebarErrorMessage();
|
2012-10-30 20:10:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-03 21:42:40 +00:00
|
|
|
// Make sure the right sidebar URL is loaded
|
2012-12-08 04:13:27 +00:00
|
|
|
if (sbrowser.getAttribute("src") != Social.provider.sidebarURL) {
|
2012-08-03 21:42:40 +00:00
|
|
|
sbrowser.setAttribute("src", Social.provider.sidebarURL);
|
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
|
|
|
}
|
2012-10-06 00:22:09 +00:00
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
SocialSidebar.setSidebarVisibilityState(true);
|
|
|
|
},
|
|
|
|
|
2012-10-24 00:09:59 +00:00
|
|
|
unloadSidebar: function SocialSidebar_unloadSidebar() {
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
|
|
|
if (!sbrowser.hasAttribute("origin"))
|
|
|
|
return;
|
|
|
|
|
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");
|
2012-10-24 00:09:59 +00:00
|
|
|
SocialFlyout.unload();
|
|
|
|
},
|
|
|
|
|
|
|
|
_unloadTimeoutId: 0,
|
|
|
|
|
2013-01-26 20:07:39 +00:00
|
|
|
setSidebarErrorMessage: function() {
|
2012-10-06 00:22:09 +00:00
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
2013-01-26 20:07:39 +00:00
|
|
|
// a frameworker error "trumps" a sidebar error.
|
|
|
|
if (Social.provider.errorState == "frameworker-error") {
|
|
|
|
sbrowser.setAttribute("src", "about:socialerror?mode=workerFailure");
|
|
|
|
} else {
|
|
|
|
let url = encodeURIComponent(Social.provider.sidebarURL);
|
|
|
|
sbrowser.loadURI("about:socialerror?mode=tryAgain&url=" + url, null, null);
|
2012-10-30 20:10:04 +00:00
|
|
|
}
|
2012-07-18 18:40:05 +00:00
|
|
|
}
|
|
|
|
}
|