2012-07-11 18:31:19 -07:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2013-03-26 16:15:59 -07:00
|
|
|
// the "exported" symbols
|
|
|
|
let SocialUI,
|
|
|
|
SocialChatBar,
|
|
|
|
SocialFlyout,
|
2013-09-06 10:56:01 -07:00
|
|
|
SocialMarks,
|
2013-05-06 23:02:58 -07:00
|
|
|
SocialShare,
|
2013-03-26 16:15:59 -07:00
|
|
|
SocialMenu,
|
|
|
|
SocialToolbar,
|
2013-09-09 14:37:04 -07:00
|
|
|
SocialSidebar,
|
|
|
|
SocialStatus;
|
2013-03-26 16:15:59 -07:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2012-10-04 20:32:38 -07:00
|
|
|
// The minimum sizes for the auto-resize panel code.
|
2012-10-07 23:14:55 -07:00
|
|
|
const PANEL_MIN_HEIGHT = 100;
|
2012-10-04 20:32:38 -07:00
|
|
|
const PANEL_MIN_WIDTH = 330;
|
|
|
|
|
2012-12-06 23:38:46 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "SharedFrame",
|
|
|
|
"resource:///modules/SharedFrame.jsm");
|
|
|
|
|
2013-05-06 23:02:58 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "OpenGraphBuilder", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/Social.jsm", tmp);
|
|
|
|
return tmp.OpenGraphBuilder;
|
|
|
|
});
|
|
|
|
|
2013-09-06 10:56:01 -07: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-03-26 16:15:59 -07:00
|
|
|
SocialUI = {
|
2012-12-07 20:13:27 -08:00
|
|
|
// Called on delayed startup to initialize the UI
|
2012-07-11 18:31:19 -07:00
|
|
|
init: function SocialUI_init() {
|
2012-07-15 16:12:13 -07:00
|
|
|
Services.obs.addObserver(this, "social:ambient-notification-changed", false);
|
|
|
|
Services.obs.addObserver(this, "social:profile-changed", false);
|
2012-10-30 13:10:04 -07:00
|
|
|
Services.obs.addObserver(this, "social:frameworker-error", false);
|
2012-12-07 20:13:27 -08:00
|
|
|
Services.obs.addObserver(this, "social:provider-set", false);
|
2013-02-08 11:39:25 -08:00
|
|
|
Services.obs.addObserver(this, "social:providers-changed", false);
|
2013-08-21 11:32:46 -07:00
|
|
|
Services.obs.addObserver(this, "social:provider-reload", false);
|
2013-09-04 10:01:38 -07:00
|
|
|
Services.obs.addObserver(this, "social:provider-installed", false);
|
|
|
|
Services.obs.addObserver(this, "social:provider-uninstalled", false);
|
|
|
|
Services.obs.addObserver(this, "social:provider-enabled", false);
|
|
|
|
Services.obs.addObserver(this, "social:provider-disabled", false);
|
2012-07-15 16:12:13 -07:00
|
|
|
|
2012-07-18 11:40:05 -07:00
|
|
|
Services.prefs.addObserver("social.sidebar.open", this, false);
|
2012-09-26 17:40:18 -07:00
|
|
|
Services.prefs.addObserver("social.toast-notifications.enabled", this, false);
|
2012-07-18 11:40:05 -07:00
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler.bind(this), true, true);
|
2013-09-06 10:56:01 -07:00
|
|
|
window.addEventListener("aftercustomization", function() {
|
|
|
|
if (SocialUI.enabled)
|
|
|
|
SocialMarks.populateContextMenu(SocialMarks);
|
|
|
|
}, false);
|
2012-06-22 15:01:34 -07:00
|
|
|
|
2013-03-06 22:25:31 -08:00
|
|
|
if (!Social.initialized) {
|
|
|
|
Social.init();
|
2013-08-30 11:11:20 -07:00
|
|
|
} else if (Social.providers.length > 0) {
|
|
|
|
// Social was initialized during startup in a previous window. If we have
|
|
|
|
// providers enabled initialize the UI for this window.
|
2013-02-19 17:23:47 -08:00
|
|
|
this.observe(null, "social:providers-changed", null);
|
2013-03-06 22:25:31 -08:00
|
|
|
this.observe(null, "social:provider-set", Social.provider ? Social.provider.origin : null);
|
2013-02-19 17:23:47 -08:00
|
|
|
}
|
2012-07-11 18:31:19 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Called on window unload
|
|
|
|
uninit: function SocialUI_uninit() {
|
2012-07-15 16:12:13 -07:00
|
|
|
Services.obs.removeObserver(this, "social:ambient-notification-changed");
|
|
|
|
Services.obs.removeObserver(this, "social:profile-changed");
|
2012-10-30 13:10:04 -07:00
|
|
|
Services.obs.removeObserver(this, "social:frameworker-error");
|
2012-12-07 20:13:27 -08:00
|
|
|
Services.obs.removeObserver(this, "social:provider-set");
|
2013-02-08 11:39:25 -08:00
|
|
|
Services.obs.removeObserver(this, "social:providers-changed");
|
2013-08-21 11:32:46 -07:00
|
|
|
Services.obs.removeObserver(this, "social:provider-reload");
|
2013-09-04 10:01:38 -07:00
|
|
|
Services.obs.removeObserver(this, "social:provider-installed");
|
|
|
|
Services.obs.removeObserver(this, "social:provider-uninstalled");
|
|
|
|
Services.obs.removeObserver(this, "social:provider-enabled");
|
|
|
|
Services.obs.removeObserver(this, "social:provider-disabled");
|
2012-07-18 11:40:05 -07:00
|
|
|
|
|
|
|
Services.prefs.removeObserver("social.sidebar.open", this);
|
2012-09-26 17:40:18 -07:00
|
|
|
Services.prefs.removeObserver("social.toast-notifications.enabled", this);
|
2012-07-11 18:31:19 -07:00
|
|
|
},
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
_matchesCurrentProvider: function (origin) {
|
|
|
|
return Social.provider && Social.provider.origin == origin;
|
|
|
|
},
|
2012-06-22 15:01:34 -07:00
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
observe: function SocialUI_observe(subject, topic, data) {
|
|
|
|
// Exceptions here sometimes don't get reported properly, report them
|
|
|
|
// manually :(
|
|
|
|
try {
|
|
|
|
switch (topic) {
|
2013-09-04 10:01:38 -07:00
|
|
|
case "social:provider-installed":
|
2013-09-06 10:56:01 -07:00
|
|
|
SocialMarks.setPosition(data);
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialStatus.setPosition(data);
|
|
|
|
break;
|
|
|
|
case "social:provider-uninstalled":
|
2013-09-06 10:56:01 -07:00
|
|
|
SocialMarks.removePosition(data);
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialStatus.removePosition(data);
|
|
|
|
break;
|
|
|
|
case "social:provider-enabled":
|
2013-09-06 10:56:01 -07:00
|
|
|
SocialMarks.populateToolbarPalette();
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialStatus.populateToolbarPalette();
|
|
|
|
break;
|
|
|
|
case "social:provider-disabled":
|
2013-09-06 10:56:01 -07:00
|
|
|
SocialMarks.removeProvider(data);
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialStatus.removeProvider(data);
|
|
|
|
break;
|
2013-08-21 11:32:46 -07:00
|
|
|
case "social:provider-reload":
|
|
|
|
// if the reloaded provider is our current provider, fall through
|
|
|
|
// to social:provider-set so the ui will be reset
|
|
|
|
if (!Social.provider || Social.provider.origin != data)
|
|
|
|
return;
|
|
|
|
// be sure to unload the sidebar as it will not reload if the origin
|
|
|
|
// has not changed, it will be loaded in provider-set below. Other
|
|
|
|
// panels will be unloaded or handle reload.
|
|
|
|
SocialSidebar.unloadSidebar();
|
|
|
|
// fall through to social:provider-set
|
2012-12-07 20:13:27 -08:00
|
|
|
case "social:provider-set":
|
2013-03-06 22:25:31 -08:00
|
|
|
// Social.provider has changed (possibly to null), update any state
|
|
|
|
// which depends on it.
|
|
|
|
this._updateActiveUI();
|
|
|
|
this._updateMenuItems();
|
|
|
|
|
2013-03-18 12:44:04 -07:00
|
|
|
SocialFlyout.unload();
|
2013-03-06 22:25:31 -08:00
|
|
|
SocialChatBar.update();
|
2013-05-06 23:02:58 -07:00
|
|
|
SocialShare.update();
|
2013-03-06 22:25:31 -08:00
|
|
|
SocialSidebar.update();
|
|
|
|
SocialToolbar.update();
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialStatus.populateToolbarPalette();
|
2013-09-06 10:56:01 -07:00
|
|
|
SocialMarks.populateToolbarPalette();
|
2013-03-06 22:25:31 -08:00
|
|
|
SocialMenu.populate();
|
2012-12-07 20:13:27 -08:00
|
|
|
break;
|
2013-02-08 11:39:25 -08:00
|
|
|
case "social:providers-changed":
|
|
|
|
// the list of providers changed - this may impact the "active" UI.
|
|
|
|
this._updateActiveUI();
|
|
|
|
// and the multi-provider menu
|
|
|
|
SocialToolbar.populateProviderMenus();
|
2013-05-06 23:02:58 -07:00
|
|
|
SocialShare.populateProviderMenu();
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialStatus.populateToolbarPalette();
|
2013-09-06 10:56:01 -07:00
|
|
|
SocialMarks.populateToolbarPalette();
|
2013-02-08 11:39:25 -08:00
|
|
|
break;
|
2012-12-07 20:13:27 -08:00
|
|
|
|
|
|
|
// Provider-specific notifications
|
|
|
|
case "social:ambient-notification-changed":
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialStatus.updateNotification(data);
|
2012-12-07 20:13:27 -08:00
|
|
|
if (this._matchesCurrentProvider(data)) {
|
|
|
|
SocialToolbar.updateButton();
|
|
|
|
SocialMenu.populate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "social:profile-changed":
|
2013-09-30 11:05:17 -07:00
|
|
|
// 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.
|
2012-12-07 20:13:27 -08:00
|
|
|
if (this._matchesCurrentProvider(data)) {
|
2013-06-19 10:14:47 -07:00
|
|
|
SocialToolbar.updateProvider();
|
2012-12-07 20:13:27 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "social:frameworker-error":
|
2013-01-24 02:14:36 -08:00
|
|
|
if (this.enabled && Social.provider.origin == data) {
|
2013-01-26 12:07:39 -08:00
|
|
|
SocialSidebar.setSidebarErrorMessage();
|
2012-12-07 20:13:27 -08:00
|
|
|
}
|
|
|
|
break;
|
2012-07-22 20:49:28 -07:00
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
case "nsPref:changed":
|
|
|
|
if (data == "social.sidebar.open") {
|
|
|
|
SocialSidebar.update();
|
2013-01-20 20:38:35 -08:00
|
|
|
} else if (data == "social.toast-notifications.enabled") {
|
|
|
|
SocialToolbar.updateButton();
|
2012-12-07 20:13:27 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2013-01-07 12:42:02 -08:00
|
|
|
Components.utils.reportError(e + "\n" + e.stack);
|
2012-12-07 20:13:27 -08:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
},
|
2012-10-29 23:28:31 -07:00
|
|
|
|
2012-12-11 15:41:42 -08:00
|
|
|
nonBrowserWindowInit: function SocialUI_nonBrowserInit() {
|
|
|
|
// Disable the social menu item in non-browser windows
|
|
|
|
document.getElementById("menu_socialAmbientMenu").hidden = true;
|
|
|
|
},
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
// Miscellaneous helpers
|
|
|
|
showProfile: function SocialUI_showProfile() {
|
2013-08-21 11:32:46 -07:00
|
|
|
if (Social.provider.haveLoggedInUser())
|
2012-12-07 20:13:27 -08:00
|
|
|
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 15:01:34 -07:00
|
|
|
},
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
_updateActiveUI: function SocialUI_updateActiveUI() {
|
2013-01-24 02:14:36 -08:00
|
|
|
// The "active" UI isn't dependent on there being a provider, just on
|
|
|
|
// social being "active" (but also chromeless/PB)
|
2013-02-08 11:39:25 -08:00
|
|
|
let enabled = Social.providers.length > 0 && !this._chromeless &&
|
2013-01-29 10:12:13 -08:00
|
|
|
!PrivateBrowsingUtils.isWindowPrivate(window);
|
2012-12-07 20:13:27 -08:00
|
|
|
let broadcaster = document.getElementById("socialActiveBroadcaster");
|
2013-01-24 02:14:36 -08:00
|
|
|
broadcaster.hidden = !enabled;
|
2012-12-07 20:13:27 -08:00
|
|
|
|
|
|
|
let toggleCommand = document.getElementById("Social:Toggle");
|
2013-01-24 02:14:36 -08:00
|
|
|
toggleCommand.setAttribute("hidden", enabled ? "false" : "true");
|
2013-02-04 21:42:18 -08:00
|
|
|
|
|
|
|
if (enabled) {
|
2013-02-08 11:39:25 -08:00
|
|
|
// enabled == true means we at least have a defaultProvider
|
|
|
|
let provider = Social.provider || Social.defaultProvider;
|
2013-02-04 21:42:18 -08:00
|
|
|
// We only need to update the command itself - all our menu items use it.
|
2013-09-19 09:25:56 -07:00
|
|
|
let label;
|
|
|
|
if (Social.providers.length == 1) {
|
|
|
|
label = gNavigatorBundle.getFormattedString(Social.provider
|
|
|
|
? "social.turnOff.label"
|
|
|
|
: "social.turnOn.label",
|
|
|
|
[provider.name]);
|
|
|
|
} else {
|
|
|
|
label = gNavigatorBundle.getString(Social.provider
|
|
|
|
? "social.turnOffAll.label"
|
|
|
|
: "social.turnOnAll.label");
|
|
|
|
}
|
|
|
|
let accesskey = gNavigatorBundle.getString(Social.provider
|
|
|
|
? "social.turnOff.accesskey"
|
|
|
|
: "social.turnOn.accesskey");
|
2013-02-04 21:42:18 -08:00
|
|
|
toggleCommand.setAttribute("label", label);
|
|
|
|
toggleCommand.setAttribute("accesskey", accesskey);
|
|
|
|
}
|
2012-07-22 20:49:28 -07:00
|
|
|
},
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
_updateMenuItems: function () {
|
2013-03-22 16:30:54 -07:00
|
|
|
let provider = Social.provider || Social.defaultProvider;
|
|
|
|
if (!provider)
|
2013-03-22 15:58:16 -07:00
|
|
|
return;
|
2012-12-07 20:13:27 -08:00
|
|
|
// The View->Sidebar and Menubar->Tools menu.
|
|
|
|
for (let id of ["menu_socialSidebar", "menu_socialAmbientMenu"])
|
2013-03-22 16:30:54 -07:00
|
|
|
document.getElementById(id).setAttribute("label", provider.name);
|
2012-11-26 22:54:55 -08:00
|
|
|
},
|
|
|
|
|
2012-06-22 15:01:34 -07:00
|
|
|
// This handles "ActivateSocialFeature" events fired against content documents
|
|
|
|
// in this window.
|
|
|
|
_activationEventHandler: function SocialUI_activationHandler(e) {
|
2013-03-05 11:24:30 -08:00
|
|
|
let targetDoc;
|
|
|
|
let node;
|
|
|
|
if (e.target instanceof HTMLDocument) {
|
|
|
|
// version 0 support
|
|
|
|
targetDoc = e.target;
|
|
|
|
node = targetDoc.documentElement
|
|
|
|
} else {
|
|
|
|
targetDoc = e.target.ownerDocument;
|
|
|
|
node = e.target;
|
|
|
|
}
|
2012-06-22 15:01:34 -07:00
|
|
|
if (!(targetDoc instanceof HTMLDocument))
|
|
|
|
return;
|
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
// Ignore events fired in background tabs or iframes
|
|
|
|
if (targetDoc.defaultView != content)
|
2012-06-22 15:01:34 -07:00
|
|
|
return;
|
|
|
|
|
2013-01-24 02:14:36 -08: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 15:01:34 -07: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;
|
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
// We only want to activate if it is as a result of user input.
|
|
|
|
let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
if (!dwu.isHandlingUserInput) {
|
|
|
|
Cu.reportError("attempt to activate provider without user input from " + targetDoc.nodePrincipal.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = node.getAttribute("data-service");
|
|
|
|
if (data) {
|
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError("Social Service manifest parse error: "+e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-03-21 13:34:26 -07:00
|
|
|
Social.installProvider(targetDoc, data, function(manifest) {
|
2013-03-05 11:24:30 -08:00
|
|
|
this.doActivation(manifest.origin);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
doActivation: function SocialUI_doActivation(origin) {
|
2012-12-07 20:13:27 -08:00
|
|
|
// Keep track of the old provider in case of undo
|
|
|
|
let oldOrigin = Social.provider ? Social.provider.origin : "";
|
|
|
|
|
2012-06-22 15:01:34 -07:00
|
|
|
// Enable the social functionality, and indicate that it was activated
|
2013-03-05 11:24:30 -08:00
|
|
|
Social.activateFromOrigin(origin, function(provider) {
|
2013-02-08 11:39:25 -08:00
|
|
|
// 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");
|
2013-04-02 16:28:30 -07:00
|
|
|
let labels = description.getElementsByTagName("label");
|
|
|
|
let uri = Services.io.newURI(provider.origin, null, null)
|
|
|
|
labels[0].setAttribute("value", uri.host);
|
|
|
|
labels[1].setAttribute("onclick", "BrowserOpenAddonsMgr('addons://list/service'); SocialUI.activationPanel.hidePopup();")
|
2013-02-08 11:39:25 -08:00
|
|
|
|
2013-02-19 05:32:49 -08:00
|
|
|
let icon = document.getElementById("social-activation-icon");
|
|
|
|
if (provider.icon64URL || provider.icon32URL) {
|
|
|
|
icon.setAttribute('src', provider.icon64URL || provider.icon32URL);
|
|
|
|
icon.hidden = false;
|
|
|
|
} else {
|
|
|
|
icon.removeAttribute('src');
|
|
|
|
icon.hidden = true;
|
|
|
|
}
|
|
|
|
|
2013-04-02 16:28:30 -07:00
|
|
|
let notificationPanel = SocialUI.activationPanel;
|
2013-02-08 11:39:25 -08:00
|
|
|
// 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 15:01:34 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
undoActivation: function SocialUI_undoActivation() {
|
2013-04-02 16:28:30 -07:00
|
|
|
let origin = this.activationPanel.getAttribute("origin");
|
|
|
|
let oldOrigin = this.activationPanel.getAttribute("oldorigin");
|
2012-12-07 20:13:27 -08:00
|
|
|
Social.deactivateFromOrigin(origin, oldOrigin);
|
2013-04-02 16:28:30 -07:00
|
|
|
this.activationPanel.hidePopup();
|
2013-03-05 11:24:30 -08:00
|
|
|
Social.uninstallProvider(origin);
|
2012-09-23 16:49:28 -07:00
|
|
|
},
|
|
|
|
|
2013-04-02 16:28:30 -07:00
|
|
|
showLearnMore: function() {
|
|
|
|
this.activationPanel.hidePopup();
|
|
|
|
let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "social-api";
|
|
|
|
openUILinkIn(url, "tab");
|
|
|
|
},
|
|
|
|
|
|
|
|
get activationPanel() {
|
2012-12-07 20:13:27 -08:00
|
|
|
return document.getElementById("socialActivatedNotification");
|
2012-10-15 23:58:13 -07: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 09:30:00 -07:00
|
|
|
// allow the link traversal to finish before closing the panel
|
|
|
|
setTimeout(() => {
|
|
|
|
containerParent.hidePopup();
|
|
|
|
}, 0);
|
2012-10-15 23:58:13 -07:00
|
|
|
}
|
2012-10-29 23:25:53 -07:00
|
|
|
},
|
|
|
|
|
2013-01-24 02:14:36 -08:00
|
|
|
get _chromeless() {
|
|
|
|
// Is this a popup window that doesn't want chrome shown?
|
|
|
|
let docElem = document.documentElement;
|
2013-06-14 13:39:42 -07:00
|
|
|
// extrachrome is not restored during session restore, so we need
|
|
|
|
// to check for the toolbar as well.
|
|
|
|
let chromeless = docElem.getAttribute("chromehidden").contains("extrachrome") ||
|
|
|
|
docElem.getAttribute('chromehidden').contains("toolbar");
|
2013-01-24 02:14:36 -08: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 10:12:13 -08:00
|
|
|
if (this._chromeless || PrivateBrowsingUtils.isWindowPrivate(window))
|
2013-01-24 02:14:36 -08:00
|
|
|
return false;
|
2013-02-08 11:39:25 -08:00
|
|
|
return !!Social.provider;
|
2013-01-24 02:14:36 -08:00
|
|
|
},
|
|
|
|
|
2013-09-06 10:56:01 -07:00
|
|
|
// called on tab/urlbar/location changes and after customization. Update
|
|
|
|
// anything that is tab specific.
|
|
|
|
updateState: function() {
|
|
|
|
if (!this.enabled)
|
|
|
|
return;
|
|
|
|
SocialMarks.update();
|
|
|
|
SocialShare.update();
|
|
|
|
}
|
2012-07-11 18:31:19 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 16:15:59 -07:00
|
|
|
SocialChatBar = {
|
2012-08-20 17:52:26 -07:00
|
|
|
get chatbar() {
|
|
|
|
return document.getElementById("pinnedchats");
|
|
|
|
},
|
2012-11-12 19:52:06 -08:00
|
|
|
// Whether the chatbar is available for this window. Note that in full-screen
|
|
|
|
// mode chats are available, but not shown.
|
|
|
|
get isAvailable() {
|
2013-08-15 15:30:02 -07:00
|
|
|
return SocialUI.enabled;
|
2012-08-20 17:52:26 -07:00
|
|
|
},
|
2012-12-06 15:56:17 -08:00
|
|
|
// Does this chatbar have any chats (whether minimized, collapsed or normal)
|
|
|
|
get hasChats() {
|
|
|
|
return !!this.chatbar.firstElementChild;
|
|
|
|
},
|
2012-08-26 16:51:24 -07:00
|
|
|
openChat: function(aProvider, aURL, aCallback, aMode) {
|
2013-03-04 16:32:33 -08:00
|
|
|
if (!this.isAvailable)
|
|
|
|
return false;
|
|
|
|
this.chatbar.openChat(aProvider, aURL, aCallback, aMode);
|
|
|
|
// We only want to focus the chat if it is as a result of user input.
|
|
|
|
let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
if (dwu.isHandlingUserInput)
|
|
|
|
this.chatbar.focus();
|
|
|
|
return true;
|
2012-08-20 17:52:26 -07:00
|
|
|
},
|
|
|
|
update: function() {
|
2012-11-26 22:58:55 -08:00
|
|
|
let command = document.getElementById("Social:FocusChat");
|
|
|
|
if (!this.isAvailable) {
|
2013-03-05 11:24:30 -08:00
|
|
|
this.chatbar.hidden = command.hidden = true;
|
2012-11-26 22:58:55 -08:00
|
|
|
} else {
|
2013-05-31 15:52:48 -07:00
|
|
|
this.chatbar.hidden = command.hidden = false;
|
2012-11-12 19:52:06 -08:00
|
|
|
}
|
2012-11-26 22:58:55 -08:00
|
|
|
command.setAttribute("disabled", command.hidden ? "true" : "false");
|
2012-10-23 23:45:59 -07:00
|
|
|
},
|
|
|
|
focus: function SocialChatBar_focus() {
|
2012-11-19 17:54:50 -08:00
|
|
|
this.chatbar.focus();
|
2012-08-20 17:52:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 16:15:59 -07:00
|
|
|
SocialFlyout = {
|
2012-08-23 17:11:02 -07:00
|
|
|
get panel() {
|
|
|
|
return document.getElementById("social-flyout-panel");
|
|
|
|
},
|
|
|
|
|
2013-05-31 13:22:51 -07:00
|
|
|
get iframe() {
|
|
|
|
if (!this.panel.firstChild)
|
|
|
|
this._createFrame();
|
|
|
|
return this.panel.firstChild;
|
|
|
|
},
|
|
|
|
|
2012-08-23 17:11:02 -07:00
|
|
|
dispatchPanelEvent: function(name) {
|
2013-05-31 13:22:51 -07:00
|
|
|
let doc = this.iframe.contentDocument;
|
2012-08-23 17:11:02 -07:00
|
|
|
let evt = doc.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent(name, true, true, {});
|
|
|
|
doc.documentElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createFrame: function() {
|
|
|
|
let panel = this.panel;
|
2013-01-24 02:14:36 -08:00
|
|
|
if (!SocialUI.enabled || panel.firstChild)
|
2012-08-23 17:11:02 -07:00
|
|
|
return;
|
|
|
|
// create and initialize the panel for this window
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
iframe.setAttribute("type", "content");
|
2012-09-06 16:13:37 -07:00
|
|
|
iframe.setAttribute("class", "social-panel-frame");
|
2012-08-23 17:11:02 -07:00
|
|
|
iframe.setAttribute("flex", "1");
|
2013-03-18 12:43:51 -07:00
|
|
|
iframe.setAttribute("tooltip", "aHTMLTooltip");
|
2012-08-23 17:11:02 -07:00
|
|
|
iframe.setAttribute("origin", Social.provider.origin);
|
|
|
|
panel.appendChild(iframe);
|
|
|
|
},
|
|
|
|
|
2012-10-05 17:22:09 -07:00
|
|
|
setFlyoutErrorMessage: function SF_setFlyoutErrorMessage() {
|
2013-05-31 13:22:51 -07:00
|
|
|
this.iframe.removeAttribute("src");
|
|
|
|
this.iframe.webNavigation.loadURI("about:socialerror?mode=compactInfo", null, null, null, null);
|
|
|
|
sizeSocialPanelToContent(this.panel, this.iframe);
|
2012-10-05 17:22:09 -07:00
|
|
|
},
|
|
|
|
|
2012-08-23 17:11:02 -07:00
|
|
|
unload: function() {
|
|
|
|
let panel = this.panel;
|
2012-09-25 23:23:25 -07:00
|
|
|
panel.hidePopup();
|
2012-08-23 17:11:02 -07:00
|
|
|
if (!panel.firstChild)
|
|
|
|
return
|
2013-01-26 12:07:39 -08:00
|
|
|
let iframe = panel.firstChild;
|
|
|
|
if (iframe.socialErrorListener)
|
|
|
|
iframe.socialErrorListener.remove();
|
|
|
|
panel.removeChild(iframe);
|
2012-08-23 17:11:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onShown: function(aEvent) {
|
2012-10-07 23:14:55 -07:00
|
|
|
let panel = this.panel;
|
2013-05-31 13:22:51 -07:00
|
|
|
let iframe = this.iframe;
|
2012-10-04 20:32:38 -07:00
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
2012-08-23 17:11:02 -07:00
|
|
|
iframe.docShell.isActive = true;
|
|
|
|
iframe.docShell.isAppTab = true;
|
|
|
|
if (iframe.contentDocument.readyState == "complete") {
|
2012-10-07 23:14:55 -07:00
|
|
|
this._dynamicResizer.start(panel, iframe);
|
2012-08-23 17:11:02 -07: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-26 22:56:22 -08:00
|
|
|
if (SocialFlyout._dynamicResizer) { // may go null if hidden quickly
|
|
|
|
SocialFlyout._dynamicResizer.start(panel, iframe);
|
|
|
|
SocialFlyout.dispatchPanelEvent("socialFrameShow");
|
|
|
|
}
|
2012-08-23 17:11:02 -07:00
|
|
|
}, 0);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onHidden: function(aEvent) {
|
2012-10-04 20:32:38 -07:00
|
|
|
this._dynamicResizer.stop();
|
|
|
|
this._dynamicResizer = null;
|
2013-05-31 13:22:51 -07:00
|
|
|
this.iframe.docShell.isActive = false;
|
2012-08-23 17:11:02 -07:00
|
|
|
this.dispatchPanelEvent("socialFrameHide");
|
|
|
|
},
|
|
|
|
|
2013-05-31 13:22:51 -07:00
|
|
|
load: function(aURL, cb) {
|
|
|
|
if (!Social.provider)
|
|
|
|
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);
|
|
|
|
// Force a layout flush by calling .clientTop so
|
|
|
|
// that the docShell of this frame is created
|
|
|
|
iframe.clientTop;
|
|
|
|
Social.setErrorListener(iframe, SocialFlyout.setFlyoutErrorMessage.bind(SocialFlyout))
|
|
|
|
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-23 17:11:02 -07:00
|
|
|
open: function(aURL, yOffset, aCallback) {
|
2012-10-21 17:28:37 -07:00
|
|
|
// Hide any other social panels that may be open.
|
|
|
|
document.getElementById("social-notification-panel").hidePopup();
|
|
|
|
|
2013-01-24 02:14:36 -08:00
|
|
|
if (!SocialUI.enabled)
|
2012-08-23 17:11:02 -07:00
|
|
|
return;
|
|
|
|
let panel = this.panel;
|
2013-05-31 13:22:51 -07:00
|
|
|
let iframe = this.iframe;
|
2012-08-23 17:11:02 -07:00
|
|
|
|
2013-05-31 13:22:51 -07: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-23 17:11:02 -07:00
|
|
|
}
|
|
|
|
}
|
2013-05-31 13:22:51 -07:00
|
|
|
});
|
2012-08-23 17:11:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:02:58 -07:00
|
|
|
SocialShare = {
|
|
|
|
get panel() {
|
|
|
|
return document.getElementById("social-share-panel");
|
|
|
|
},
|
|
|
|
|
|
|
|
get iframe() {
|
|
|
|
// first element is our menu vbox.
|
|
|
|
if (this.panel.childElementCount == 1)
|
|
|
|
return null;
|
|
|
|
else
|
|
|
|
return this.panel.lastChild;
|
|
|
|
},
|
|
|
|
|
|
|
|
_createFrame: function() {
|
|
|
|
let panel = this.panel;
|
|
|
|
if (!SocialUI.enabled || this.iframe)
|
|
|
|
return;
|
|
|
|
this.panel.hidden = false;
|
|
|
|
// create and initialize the panel for this window
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
iframe.setAttribute("type", "content");
|
|
|
|
iframe.setAttribute("class", "social-share-frame");
|
2013-07-29 10:53:00 -07:00
|
|
|
iframe.setAttribute("context", "contentAreaContextMenu");
|
|
|
|
iframe.setAttribute("tooltip", "aHTMLTooltip");
|
2013-05-06 23:02:58 -07:00
|
|
|
iframe.setAttribute("flex", "1");
|
|
|
|
panel.appendChild(iframe);
|
|
|
|
this.populateProviderMenu();
|
|
|
|
},
|
2013-07-29 10:53:00 -07:00
|
|
|
|
2013-05-06 23:02:58 -07:00
|
|
|
getSelectedProvider: function() {
|
|
|
|
let provider;
|
|
|
|
let lastProviderOrigin = this.iframe && this.iframe.getAttribute("origin");
|
|
|
|
if (lastProviderOrigin) {
|
|
|
|
provider = Social._getProviderFromOrigin(lastProviderOrigin);
|
|
|
|
}
|
|
|
|
if (!provider)
|
|
|
|
provider = Social.provider || Social.defaultProvider;
|
|
|
|
// if our provider has no shareURL, select the first one that does
|
|
|
|
if (provider && !provider.shareURL) {
|
|
|
|
let providers = [p for (p of Social.providers) if (p.shareURL)];
|
|
|
|
provider = providers.length > 0 && providers[0];
|
|
|
|
}
|
|
|
|
return provider;
|
|
|
|
},
|
|
|
|
|
|
|
|
populateProviderMenu: function() {
|
|
|
|
if (!this.iframe)
|
|
|
|
return;
|
|
|
|
let providers = [p for (p of Social.providers) if (p.shareURL)];
|
|
|
|
let hbox = document.getElementById("social-share-provider-buttons");
|
|
|
|
// selectable providers are inserted before the provider-menu seperator,
|
|
|
|
// remove any menuitems in that area
|
|
|
|
while (hbox.firstChild) {
|
|
|
|
hbox.removeChild(hbox.firstChild);
|
|
|
|
}
|
|
|
|
// reset our share toolbar
|
|
|
|
// only show a selection if there is more than one
|
|
|
|
if (!SocialUI.enabled || providers.length < 2) {
|
|
|
|
this.panel.firstChild.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let selectedProvider = this.getSelectedProvider();
|
|
|
|
for (let provider of providers) {
|
|
|
|
let button = document.createElement("toolbarbutton");
|
|
|
|
button.setAttribute("class", "toolbarbutton share-provider-button");
|
|
|
|
button.setAttribute("type", "radio");
|
|
|
|
button.setAttribute("group", "share-providers");
|
|
|
|
button.setAttribute("image", provider.iconURL);
|
|
|
|
button.setAttribute("tooltiptext", provider.name);
|
|
|
|
button.setAttribute("origin", provider.origin);
|
|
|
|
button.setAttribute("oncommand", "SocialShare.sharePage(this.getAttribute('origin')); this.checked=true;");
|
|
|
|
if (provider == selectedProvider) {
|
|
|
|
this.defaultButton = button;
|
|
|
|
}
|
|
|
|
hbox.appendChild(button);
|
|
|
|
}
|
|
|
|
if (!this.defaultButton) {
|
|
|
|
this.defaultButton = hbox.firstChild
|
|
|
|
}
|
|
|
|
this.defaultButton.setAttribute("checked", "true");
|
|
|
|
this.panel.firstChild.hidden = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
get shareButton() {
|
|
|
|
return document.getElementById("social-share-button");
|
|
|
|
},
|
|
|
|
|
|
|
|
canSharePage: function(aURI) {
|
|
|
|
// we do not enable sharing from private sessions
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(window))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!aURI || !(aURI.schemeIs('http') || aURI.schemeIs('https')))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function() {
|
|
|
|
let shareButton = this.shareButton;
|
|
|
|
shareButton.hidden = !SocialUI.enabled ||
|
|
|
|
[p for (p of Social.providers) if (p.shareURL)].length == 0;
|
|
|
|
shareButton.disabled = shareButton.hidden || !this.canSharePage(gBrowser.currentURI);
|
|
|
|
|
|
|
|
// 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.disabled ? "true" : "false");
|
|
|
|
},
|
|
|
|
|
|
|
|
onShowing: function() {
|
|
|
|
this.shareButton.setAttribute("open", "true");
|
|
|
|
},
|
|
|
|
|
|
|
|
onHidden: function() {
|
|
|
|
this.shareButton.removeAttribute("open");
|
2013-08-30 09:30:00 -07:00
|
|
|
this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
|
2013-05-06 23:02:58 -07:00
|
|
|
this.currentShare = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
setErrorMessage: function() {
|
|
|
|
let iframe = this.iframe;
|
|
|
|
if (!iframe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
iframe.removeAttribute("src");
|
|
|
|
iframe.webNavigation.loadURI("about:socialerror?mode=compactInfo&origin=" +
|
|
|
|
encodeURIComponent(iframe.getAttribute("origin")),
|
|
|
|
null, null, null, null);
|
|
|
|
sizeSocialPanelToContent(this.panel, iframe);
|
|
|
|
},
|
|
|
|
|
|
|
|
sharePage: function(providerOrigin, graphData) {
|
|
|
|
// 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;
|
|
|
|
let provider;
|
|
|
|
if (providerOrigin)
|
|
|
|
provider = Social._getProviderFromOrigin(providerOrigin);
|
|
|
|
else
|
|
|
|
provider = this.getSelectedProvider();
|
|
|
|
if (!provider || !provider.shareURL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
let sharedURI = graphData ? Services.io.newURI(graphData.url, null, null) :
|
|
|
|
gBrowser.currentURI;
|
|
|
|
if (!this.canSharePage(sharedURI))
|
|
|
|
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.
|
|
|
|
let pageData = graphData ? graphData : this.currentShare;
|
|
|
|
if (!pageData || sharedURI == gBrowser.currentURI) {
|
|
|
|
pageData = OpenGraphBuilder.getData(gBrowser);
|
|
|
|
if (graphData) {
|
|
|
|
// overwrite data retreived from page with data given to us as a param
|
|
|
|
for (let p in graphData) {
|
|
|
|
pageData[p] = graphData[p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.currentShare = pageData;
|
|
|
|
|
2013-09-06 10:56:01 -07:00
|
|
|
let shareEndpoint = OpenGraphBuilder.generateEndpointURL(provider.shareURL, pageData);
|
2013-05-06 23:02:58 -07:00
|
|
|
|
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
|
|
|
// if we've already loaded this provider/page share endpoint, we don't want
|
|
|
|
// to add another load event listener.
|
|
|
|
let reload = true;
|
|
|
|
let endpointMatch = shareEndpoint == iframe.getAttribute("src");
|
|
|
|
let docLoaded = iframe.contentDocument && iframe.contentDocument.readyState == "complete";
|
|
|
|
if (endpointMatch && docLoaded) {
|
|
|
|
reload = shareEndpoint != iframe.contentDocument.location.spec;
|
|
|
|
}
|
|
|
|
if (!reload) {
|
|
|
|
this._dynamicResizer.start(this.panel, iframe);
|
|
|
|
iframe.docShell.isActive = true;
|
|
|
|
iframe.docShell.isAppTab = true;
|
|
|
|
let evt = iframe.contentDocument.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(pageData));
|
|
|
|
iframe.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
} else {
|
|
|
|
// first time load, wait for load and dispatch after load
|
|
|
|
iframe.addEventListener("load", function panelBrowserOnload(e) {
|
|
|
|
iframe.removeEventListener("load", panelBrowserOnload, true);
|
|
|
|
iframe.docShell.isActive = true;
|
|
|
|
iframe.docShell.isAppTab = true;
|
|
|
|
setTimeout(function() {
|
|
|
|
if (SocialShare._dynamicResizer) { // may go null if hidden quickly
|
|
|
|
SocialShare._dynamicResizer.start(iframe.parentNode, iframe);
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
let evt = iframe.contentDocument.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(pageData));
|
|
|
|
iframe.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
let navBar = document.getElementById("nav-bar");
|
2013-06-10 19:47:02 -07:00
|
|
|
let anchor = document.getAnonymousElementByAttribute(this.shareButton, "class", "toolbarbutton-icon");
|
2013-05-06 23:02:58 -07:00
|
|
|
this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
|
|
|
|
Social.setErrorListener(iframe, this.setErrorMessage.bind(this));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:15:59 -07:00
|
|
|
SocialMenu = {
|
2012-10-11 18:21:50 -07:00
|
|
|
populate: function SocialMenu_populate() {
|
2012-11-15 15:07:42 -08:00
|
|
|
let submenu = document.getElementById("menu_social-statusarea-popup");
|
2012-10-21 17:25:19 -07:00
|
|
|
let ambientMenuItems = submenu.getElementsByClassName("ambient-menuitem");
|
2012-11-09 15:36:22 -08:00
|
|
|
while (ambientMenuItems.length)
|
|
|
|
submenu.removeChild(ambientMenuItems.item(0));
|
2012-10-25 12:30:59 -07:00
|
|
|
|
|
|
|
let separator = document.getElementById("socialAmbientMenuSeparator");
|
|
|
|
separator.hidden = true;
|
2013-01-24 02:14:36 -08:00
|
|
|
let provider = SocialUI.enabled ? Social.provider : null;
|
|
|
|
if (!provider)
|
2012-12-07 20:13:27 -08: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-11 18:21:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
// XXX Need to audit that this is being initialized correctly
|
2013-03-26 16:15:59 -07:00
|
|
|
SocialToolbar = {
|
2012-12-07 20:13:27 -08:00
|
|
|
// Called once, after window load, when the Social.provider object is
|
|
|
|
// initialized.
|
2013-08-12 12:06:22 -07:00
|
|
|
get _dynamicResizer() {
|
|
|
|
delete this._dynamicResizer;
|
2012-12-07 20:13:27 -08:00
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
2013-08-12 12:06:22 -07:00
|
|
|
return this._dynamicResizer;
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
2013-03-06 22:25:31 -08:00
|
|
|
update: function() {
|
|
|
|
this._updateButtonHiddenState();
|
|
|
|
this.updateProvider();
|
|
|
|
this.populateProviderMenus();
|
|
|
|
},
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
// Called when the Social.provider changes
|
|
|
|
updateProvider: function () {
|
2013-05-06 11:25:24 -07:00
|
|
|
let provider = Social.provider;
|
2013-02-08 11:39:25 -08:00
|
|
|
if (provider) {
|
|
|
|
this.button.setAttribute("label", provider.name);
|
|
|
|
this.button.setAttribute("tooltiptext", provider.name);
|
|
|
|
this.button.style.listStyleImage = "url(" + provider.iconURL + ")";
|
2013-02-04 21:42:18 -08:00
|
|
|
|
|
|
|
this.updateProfile();
|
2013-05-06 11:25:24 -07:00
|
|
|
} else {
|
|
|
|
this.button.setAttribute("label", gNavigatorBundle.getString("service.toolbarbutton.label"));
|
|
|
|
this.button.setAttribute("tooltiptext", gNavigatorBundle.getString("service.toolbarbutton.tooltiptext"));
|
|
|
|
this.button.style.removeProperty("list-style-image");
|
2013-02-04 21:42:18 -08:00
|
|
|
}
|
2012-07-15 16:12:13 -07:00
|
|
|
this.updateButton();
|
|
|
|
},
|
|
|
|
|
2012-10-03 21:00:57 -07:00
|
|
|
get button() {
|
|
|
|
return document.getElementById("social-provider-button");
|
|
|
|
},
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
// Note: this doesn't actually handle hiding the toolbar button,
|
|
|
|
// socialActiveBroadcaster is responsible for that.
|
2013-03-06 22:25:31 -08:00
|
|
|
_updateButtonHiddenState: function SocialToolbar_updateButtonHiddenState() {
|
2013-01-24 02:14:36 -08:00
|
|
|
let socialEnabled = SocialUI.enabled;
|
2012-11-15 15:07:42 -08: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);
|
|
|
|
|
2013-09-26 10:55:08 -07:00
|
|
|
// we need to remove buttons and frames if !socialEnabled or the provider
|
|
|
|
// has changed (frame origin does not match current provider). We only
|
|
|
|
// remove frames that are "attached" to buttons in this toolbar button since
|
|
|
|
// other buttons may also be using grouped frames.
|
2013-09-06 10:55:43 -07:00
|
|
|
let tbi = document.getElementById("social-provider-button");
|
2013-08-21 11:32:46 -07:00
|
|
|
if (tbi) {
|
2013-09-16 19:45:27 -07:00
|
|
|
// buttons after social-provider-button are ambient icons
|
2013-09-26 10:55:08 -07:00
|
|
|
let next = tbi.nextSibling;
|
|
|
|
let currentOrigin = Social.provider ? Social.provider.origin : null;
|
|
|
|
|
|
|
|
while (next) {
|
|
|
|
let button = next;
|
|
|
|
next = next.nextSibling;
|
|
|
|
// get the frame for this button
|
|
|
|
let frameId = button.getAttribute("notificationFrameId");
|
|
|
|
let frame = document.getElementById(frameId);
|
|
|
|
if (!socialEnabled || frame.getAttribute("origin") != currentOrigin) {
|
|
|
|
SharedFrame.forgetGroup(frame.id);
|
|
|
|
frame.parentNode.removeChild(frame);
|
|
|
|
button.parentNode.removeChild(button);
|
|
|
|
}
|
2013-03-06 22:25:31 -08:00
|
|
|
}
|
2012-08-16 18:02:23 -07:00
|
|
|
}
|
2012-07-15 16:12:13 -07: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
|
2013-02-08 11:39:25 -08:00
|
|
|
if (!Social.provider)
|
|
|
|
return;
|
2012-07-15 16:12:13 -07:00
|
|
|
let profile = Social.provider.profile || {};
|
2013-03-04 14:08:25 -08:00
|
|
|
let userPortrait = profile.portrait;
|
2012-11-15 15:07:42 -08:00
|
|
|
|
2012-11-19 17:22:42 -08:00
|
|
|
let userDetailsBroadcaster = document.getElementById("socialBroadcaster_userDetails");
|
2012-12-07 20:13:27 -08:00
|
|
|
let loggedInStatusValue = profile.userName ||
|
|
|
|
userDetailsBroadcaster.getAttribute("notLoggedInLabel");
|
2012-11-19 17:22:42 -08: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.
|
2013-03-04 14:08:25 -08:00
|
|
|
if (userPortrait) {
|
|
|
|
userDetailsBroadcaster.setAttribute("src", userPortrait);
|
|
|
|
userDetailsBroadcaster.setAttribute("image", userPortrait);
|
|
|
|
} else {
|
|
|
|
userDetailsBroadcaster.removeAttribute("src");
|
|
|
|
userDetailsBroadcaster.removeAttribute("image");
|
|
|
|
}
|
2012-11-19 17:22:42 -08:00
|
|
|
|
|
|
|
userDetailsBroadcaster.setAttribute("value", loggedInStatusValue);
|
|
|
|
userDetailsBroadcaster.setAttribute("label", loggedInStatusValue);
|
2012-07-15 16:12:13 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
updateButton: function SocialToolbar_updateButton() {
|
2013-03-06 22:25:31 -08:00
|
|
|
this._updateButtonHiddenState();
|
2012-08-23 11:23:17 -07:00
|
|
|
let panel = document.getElementById("social-notification-panel");
|
2013-02-04 21:42:18 -08:00
|
|
|
panel.hidden = !SocialUI.enabled;
|
2012-10-07 17:15:02 -07:00
|
|
|
|
|
|
|
let command = document.getElementById("Social:ToggleNotifications");
|
|
|
|
command.setAttribute("checked", Services.prefs.getBoolPref("social.toast-notifications.enabled"));
|
|
|
|
|
2012-11-28 22:14:48 -08:00
|
|
|
const CACHE_PREF_NAME = "social.cached.ambientNotificationIcons";
|
2012-10-07 17:15:02 -07: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 02:14:36 -08:00
|
|
|
if (!SocialUI.enabled ||
|
2013-08-21 11:32:46 -07:00
|
|
|
(!Social.provider.haveLoggedInUser() && Social.provider.profile !== undefined)) {
|
2012-10-23 00:47:29 -07: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-07 17:15:02 -07:00
|
|
|
Services.prefs.clearUserPref(CACHE_PREF_NAME);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-04 10:01:38 -07:00
|
|
|
|
|
|
|
// If the provider uses the new SocialStatus button, then they do not get
|
|
|
|
// to use the ambient icons in the old toolbar button. Since the status
|
|
|
|
// button depends on multiple workers, if not enabled we will ignore this
|
|
|
|
// limitation. That allows a provider to migrate to the new functionality
|
|
|
|
// once we enable multiple workers.
|
|
|
|
if (Social.provider.statusURL && Social.allowMultipleWorkers)
|
|
|
|
return;
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
let icons = Social.provider.ambientNotificationIcons;
|
2013-02-04 21:42:18 -08:00
|
|
|
let iconNames = Object.keys(icons);
|
2013-02-08 11:39:25 -08:00
|
|
|
|
2012-10-07 17:15:02 -07: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-28 22:14:48 -08:00
|
|
|
cached = JSON.parse(Services.prefs.getComplexValue(CACHE_PREF_NAME,
|
|
|
|
Ci.nsISupportsString).data);
|
2012-10-07 17:15:02 -07: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-28 22:14:48 -08: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-07 17:15:02 -07:00
|
|
|
}
|
|
|
|
|
2013-01-07 12:42:02 -08:00
|
|
|
let toolbarButtons = document.createDocumentFragment();
|
2012-08-16 18:02:23 -07:00
|
|
|
|
2012-10-05 17:22:09 -07:00
|
|
|
let createdFrames = [];
|
|
|
|
|
2012-08-16 18:02:23 -07:00
|
|
|
for each(let name in iconNames) {
|
2012-10-07 17:15:02 -07:00
|
|
|
let icon = icons[name];
|
2012-08-16 18:02:23 -07:00
|
|
|
|
2012-08-22 13:56:14 -07:00
|
|
|
let notificationFrameId = "social-status-" + icon.name;
|
|
|
|
let notificationFrame = document.getElementById(notificationFrameId);
|
2012-12-06 23:38:46 -08:00
|
|
|
|
2012-08-22 13:56:14 -07:00
|
|
|
if (!notificationFrame) {
|
2012-12-06 23:38:46 -08:00
|
|
|
notificationFrame = SharedFrame.createFrame(
|
|
|
|
notificationFrameId, /* frame name */
|
|
|
|
panel, /* parent */
|
|
|
|
{
|
|
|
|
"type": "content",
|
|
|
|
"mozbrowser": "true",
|
|
|
|
"class": "social-panel-frame",
|
|
|
|
"id": notificationFrameId,
|
2013-03-18 12:43:51 -07:00
|
|
|
"tooltip": "aHTMLTooltip",
|
2012-12-06 23:38:46 -08:00
|
|
|
|
|
|
|
// 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-08 11:39:25 -08:00
|
|
|
"origin": Social.provider.origin,
|
2012-12-06 23:38:46 -08:00
|
|
|
"src": icon.contentPanel
|
|
|
|
}
|
|
|
|
);
|
2012-10-05 17:22:09 -07:00
|
|
|
|
|
|
|
createdFrames.push(notificationFrame);
|
2012-12-06 23:38:46 -08:00
|
|
|
} else {
|
2013-02-08 11:39:25 -08:00
|
|
|
notificationFrame.setAttribute("origin", Social.provider.origin);
|
2012-12-06 23:38:46 -08:00
|
|
|
SharedFrame.updateURL(notificationFrameId, icon.contentPanel);
|
2012-07-15 16:12:13 -07:00
|
|
|
}
|
2012-08-16 18:02:23 -07:00
|
|
|
|
2013-01-07 12:42:02 -08:00
|
|
|
let toolbarButtonId = "social-notification-icon-" + icon.name;
|
|
|
|
let toolbarButton = document.getElementById(toolbarButtonId);
|
2013-04-07 23:53:41 -07:00
|
|
|
if (!toolbarButton) {
|
2013-01-07 12:42:02 -08:00
|
|
|
toolbarButton = document.createElement("toolbarbutton");
|
2013-04-07 23:53:41 -07:00
|
|
|
toolbarButton.setAttribute("type", "badged");
|
2013-01-07 12:42:02 -08:00
|
|
|
toolbarButton.classList.add("toolbarbutton-1");
|
|
|
|
toolbarButton.setAttribute("id", toolbarButtonId);
|
|
|
|
toolbarButton.setAttribute("notificationFrameId", notificationFrameId);
|
|
|
|
toolbarButton.addEventListener("mousedown", function (event) {
|
2013-02-08 08:34:46 -08:00
|
|
|
if (event.button == 0 && panel.state == "closed")
|
2013-01-07 12:42:02 -08:00
|
|
|
SocialToolbar.showAmbientPopup(toolbarButton);
|
|
|
|
});
|
|
|
|
|
2013-04-07 23:53:41 -07:00
|
|
|
toolbarButtons.appendChild(toolbarButton);
|
2012-09-29 03:17:29 -07:00
|
|
|
}
|
2012-09-27 16:57:37 -07:00
|
|
|
|
2013-01-07 12:42:02 -08:00
|
|
|
toolbarButton.style.listStyleImage = "url(" + icon.iconURL + ")";
|
|
|
|
toolbarButton.setAttribute("label", icon.label);
|
|
|
|
toolbarButton.setAttribute("tooltiptext", icon.label);
|
2012-09-27 16:57:37 -07:00
|
|
|
|
2013-01-07 12:42:02 -08:00
|
|
|
let badge = icon.counter || "";
|
2013-04-07 22:59:33 -07:00
|
|
|
toolbarButton.setAttribute("badge", badge);
|
2013-02-07 15:59:10 -08:00
|
|
|
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-16 18:02:23 -07:00
|
|
|
}
|
2013-01-07 12:42:02 -08:00
|
|
|
let socialToolbarItem = document.getElementById("social-toolbar-item");
|
2013-09-06 10:55:43 -07:00
|
|
|
socialToolbarItem.appendChild(toolbarButtons);
|
2012-10-05 17:22:09 -07:00
|
|
|
|
|
|
|
for (let frame of createdFrames) {
|
2013-09-04 10:01:38 -07:00
|
|
|
if (frame.socialErrorListener)
|
2013-01-26 12:07:39 -08:00
|
|
|
frame.socialErrorListener.remove();
|
2012-10-05 17:22:09 -07:00
|
|
|
if (frame.docShell) {
|
2012-10-05 17:22:09 -07:00
|
|
|
frame.docShell.isActive = false;
|
2013-01-26 12:07:39 -08:00
|
|
|
Social.setErrorListener(frame, this.setPanelErrorMessage.bind(this));
|
2012-10-05 17:22:09 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-15 16:12:13 -07:00
|
|
|
},
|
|
|
|
|
2013-01-07 12:42:02 -08:00
|
|
|
showAmbientPopup: function SocialToolbar_showAmbientPopup(aToolbarButton) {
|
2012-10-21 17:28:37 -07:00
|
|
|
// Hide any other social panels that may be open.
|
|
|
|
SocialFlyout.panel.hidePopup();
|
|
|
|
|
2012-07-15 16:12:13 -07:00
|
|
|
let panel = document.getElementById("social-notification-panel");
|
2013-01-07 12:42:02 -08:00
|
|
|
let notificationFrameId = aToolbarButton.getAttribute("notificationFrameId");
|
2012-09-27 16:57:37 -07:00
|
|
|
let notificationFrame = document.getElementById(notificationFrameId);
|
2012-07-15 16:12:13 -07:00
|
|
|
|
2012-12-06 23:38:46 -08:00
|
|
|
let wasAlive = SharedFrame.isGroupAlive(notificationFrameId);
|
|
|
|
SharedFrame.setOwner(notificationFrameId, notificationFrame);
|
|
|
|
|
2012-08-23 17:11:02 -07:00
|
|
|
// Clear dimensions on all browsers so the panel size will
|
|
|
|
// only use the selected browser.
|
2012-10-15 23:58:13 -07:00
|
|
|
let frameIter = panel.firstElementChild;
|
2012-08-23 17:11:02 -07:00
|
|
|
while (frameIter) {
|
|
|
|
frameIter.collapsed = (frameIter != notificationFrame);
|
|
|
|
frameIter = frameIter.nextElementSibling;
|
2012-07-15 16:12:13 -07:00
|
|
|
}
|
|
|
|
|
2012-08-20 11:25:47 -07:00
|
|
|
function dispatchPanelEvent(name) {
|
2012-08-22 13:56:14 -07:00
|
|
|
let evt = notificationFrame.contentDocument.createEvent("CustomEvent");
|
2012-08-20 11:25:47 -07:00
|
|
|
evt.initCustomEvent(name, true, true, {});
|
2012-08-22 13:56:14 -07:00
|
|
|
notificationFrame.contentDocument.documentElement.dispatchEvent(evt);
|
2012-08-20 11:25:47 -07:00
|
|
|
}
|
|
|
|
|
2012-10-04 20:32:38 -07:00
|
|
|
let dynamicResizer = this._dynamicResizer;
|
2012-08-23 17:10:07 -07:00
|
|
|
panel.addEventListener("popuphidden", function onpopuphiding() {
|
|
|
|
panel.removeEventListener("popuphidden", onpopuphiding);
|
2013-01-07 12:42:02 -08:00
|
|
|
aToolbarButton.removeAttribute("open");
|
|
|
|
aToolbarButton.parentNode.removeAttribute("open");
|
2012-10-04 20:32:38 -07:00
|
|
|
dynamicResizer.stop();
|
2012-08-23 17:10:07 -07:00
|
|
|
notificationFrame.docShell.isActive = false;
|
2012-08-20 11:25:47 -07:00
|
|
|
dispatchPanelEvent("socialFrameHide");
|
|
|
|
});
|
|
|
|
|
|
|
|
panel.addEventListener("popupshown", function onpopupshown() {
|
|
|
|
panel.removeEventListener("popupshown", onpopupshown);
|
2013-09-04 10:01:38 -07:00
|
|
|
// The "open" 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.
|
2013-01-07 12:42:02 -08:00
|
|
|
aToolbarButton.setAttribute("open", "true");
|
|
|
|
aToolbarButton.parentNode.setAttribute("open", "true");
|
2012-08-23 17:10:07 -07:00
|
|
|
notificationFrame.docShell.isActive = true;
|
2012-08-22 13:56:14 -07:00
|
|
|
notificationFrame.docShell.isAppTab = true;
|
2012-12-06 23:38:46 -08:00
|
|
|
if (notificationFrame.contentDocument.readyState == "complete" && wasAlive) {
|
2012-10-07 23:14:55 -07:00
|
|
|
dynamicResizer.start(panel, notificationFrame);
|
2012-08-20 11:25:47 -07:00
|
|
|
dispatchPanelEvent("socialFrameShow");
|
|
|
|
} else {
|
|
|
|
// first time load, wait for load and dispatch after load
|
2012-08-22 13:56:14 -07:00
|
|
|
notificationFrame.addEventListener("load", function panelBrowserOnload(e) {
|
|
|
|
notificationFrame.removeEventListener("load", panelBrowserOnload, true);
|
2012-10-07 23:14:55 -07:00
|
|
|
dynamicResizer.start(panel, notificationFrame);
|
2012-08-20 11:25:47 -07:00
|
|
|
setTimeout(function() {
|
|
|
|
dispatchPanelEvent("socialFrameShow");
|
|
|
|
}, 0);
|
|
|
|
}, true);
|
|
|
|
}
|
2012-07-15 16:12:13 -07:00
|
|
|
});
|
|
|
|
|
2013-01-16 11:07:45 -08:00
|
|
|
let navBar = document.getElementById("nav-bar");
|
2013-06-10 12:56:22 -07:00
|
|
|
let anchor = document.getAnonymousElementByAttribute(aToolbarButton, "class", "toolbarbutton-badge-container");
|
2013-03-12 15:31:39 -07:00
|
|
|
// Bug 849216 - open the popup in a setTimeout so we avoid the auto-rollup
|
|
|
|
// handling from preventing it being opened in some cases.
|
|
|
|
setTimeout(function() {
|
|
|
|
panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
|
|
|
|
}, 0);
|
2012-10-05 17:22:09 -07: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-27 17:50:03 -08:00
|
|
|
let panel = aNotificationFrame.parentNode;
|
|
|
|
sizeSocialPanelToContent(panel, aNotificationFrame);
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
populateProviderMenus: function SocialToolbar_renderProviderMenus() {
|
|
|
|
let providerMenuSeps = document.getElementsByClassName("social-provider-menu");
|
|
|
|
for (let providerMenuSep of providerMenuSeps)
|
2013-02-08 11:39:25 -08:00
|
|
|
this._populateProviderMenu(providerMenuSep);
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
_populateProviderMenu: function SocialToolbar_renderProviderMenu(providerMenuSep) {
|
2012-12-07 20:13:27 -08: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 02:14:36 -08:00
|
|
|
// only show a selection if enabled and there is more than one
|
2013-05-06 23:02:58 -07:00
|
|
|
let providers = [p for (p of Social.providers) if (p.workerURL || p.sidebarURL)];
|
|
|
|
if (providers.length < 2) {
|
2012-12-07 20:13:27 -08:00
|
|
|
providerMenuSep.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
2013-05-06 23:02:58 -07:00
|
|
|
for (let provider of providers) {
|
2012-12-07 20:13:27 -08: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 16:12:13 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-18 11:40:05 -07:00
|
|
|
|
2013-03-26 16:15:59 -07:00
|
|
|
SocialSidebar = {
|
2012-07-18 11:40:05 -07:00
|
|
|
// Whether the sidebar can be shown for this window.
|
|
|
|
get canShow() {
|
2013-01-24 02:14:36 -08:00
|
|
|
return SocialUI.enabled && Social.provider.sidebarURL;
|
2012-07-18 11:40:05 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Whether the user has toggled the sidebar on (for windows where it can appear)
|
2012-10-03 16:11:52 -07:00
|
|
|
get opened() {
|
|
|
|
return Services.prefs.getBoolPref("social.sidebar.open") && !document.mozFullScreen;
|
2012-07-18 11:40:05 -07:00
|
|
|
},
|
|
|
|
|
2012-10-29 20:52:56 -07:00
|
|
|
setSidebarVisibilityState: function(aEnabled) {
|
2012-08-03 14:42:40 -07:00
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
2012-11-13 20:27:41 -08: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 14:42:40 -07:00
|
|
|
let evt = sbrowser.contentDocument.createEvent("CustomEvent");
|
2012-10-29 20:52:56 -07:00
|
|
|
evt.initCustomEvent(aEnabled ? "socialFrameShow" : "socialFrameHide", true, true, {});
|
2012-08-03 14:42:40 -07:00
|
|
|
sbrowser.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2012-11-12 19:52:06 -08:00
|
|
|
update: function SocialSidebar_update() {
|
2012-10-23 17:09:59 -07:00
|
|
|
clearTimeout(this._unloadTimeoutId);
|
2012-07-18 11:40:05 -07:00
|
|
|
// Hide the toggle menu item if the sidebar cannot appear
|
|
|
|
let command = document.getElementById("Social:ToggleSidebar");
|
2012-10-23 00:47:33 -07:00
|
|
|
command.setAttribute("hidden", this.canShow ? "false" : "true");
|
2012-07-18 11:40:05 -07:00
|
|
|
|
|
|
|
// Hide the sidebar if it cannot appear, or has been toggled off.
|
|
|
|
// Also set the command "checked" state accordingly.
|
2012-10-03 16:11:52 -07:00
|
|
|
let hideSidebar = !this.canShow || !this.opened;
|
2012-07-18 11:40:05 -07:00
|
|
|
let broadcaster = document.getElementById("socialSidebarBroadcaster");
|
|
|
|
broadcaster.hidden = hideSidebar;
|
|
|
|
command.setAttribute("checked", !hideSidebar);
|
|
|
|
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
2012-12-07 20:13:27 -08:00
|
|
|
|
2012-08-03 14:42:40 -07:00
|
|
|
if (hideSidebar) {
|
2012-11-05 15:26:33 -08:00
|
|
|
sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
|
2012-10-29 20:52:56 -07:00
|
|
|
this.setSidebarVisibilityState(false);
|
2012-10-23 17:09:59 -07: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 14:42:40 -07:00
|
|
|
if (!this.canShow) {
|
2012-10-23 17:09:59 -07:00
|
|
|
this.unloadSidebar();
|
|
|
|
} else {
|
|
|
|
this._unloadTimeoutId = setTimeout(
|
|
|
|
this.unloadSidebar,
|
|
|
|
Services.prefs.getIntPref("social.sidebar.unload_timeout_ms")
|
|
|
|
);
|
2012-08-03 14:42:40 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-13 20:42:37 -08:00
|
|
|
sbrowser.setAttribute("origin", Social.provider.origin);
|
2012-12-07 20:13:27 -08:00
|
|
|
if (Social.provider.errorState == "frameworker-error") {
|
2013-01-26 12:07:39 -08:00
|
|
|
SocialSidebar.setSidebarErrorMessage();
|
2012-10-30 13:10:04 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-03 14:42:40 -07:00
|
|
|
// Make sure the right sidebar URL is loaded
|
2012-12-07 20:13:27 -08:00
|
|
|
if (sbrowser.getAttribute("src") != Social.provider.sidebarURL) {
|
2013-08-12 12:06:22 -07:00
|
|
|
Social.setErrorListener(sbrowser, this.setSidebarErrorMessage.bind(this));
|
|
|
|
// setting isAppTab causes clicks on untargeted links to open new tabs
|
|
|
|
sbrowser.docShell.isAppTab = true;
|
2012-08-03 14:42:40 -07:00
|
|
|
sbrowser.setAttribute("src", Social.provider.sidebarURL);
|
2013-07-29 09:35:41 -07:00
|
|
|
PopupNotifications.locationChange(sbrowser);
|
2013-07-29 09:03:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the document has not loaded, delay until it is
|
|
|
|
if (sbrowser.contentDocument.readyState != "complete") {
|
2012-11-05 15:26:33 -08:00
|
|
|
sbrowser.addEventListener("load", SocialSidebar._loadListener, true);
|
2012-08-03 14:42:40 -07:00
|
|
|
} else {
|
2012-10-29 20:52:56 -07:00
|
|
|
this.setSidebarVisibilityState(true);
|
2012-08-03 14:42:40 -07:00
|
|
|
}
|
2012-07-18 11:40:05 -07:00
|
|
|
}
|
2012-10-05 17:22:09 -07:00
|
|
|
},
|
|
|
|
|
2012-11-05 15:26:33 -08:00
|
|
|
_loadListener: function SocialSidebar_loadListener() {
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
|
|
|
sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
|
|
|
|
SocialSidebar.setSidebarVisibilityState(true);
|
|
|
|
},
|
|
|
|
|
2012-10-23 17:09:59 -07:00
|
|
|
unloadSidebar: function SocialSidebar_unloadSidebar() {
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
|
|
|
if (!sbrowser.hasAttribute("origin"))
|
|
|
|
return;
|
|
|
|
|
2012-12-12 17:13:09 -08:00
|
|
|
sbrowser.stop();
|
2012-10-23 17:09:59 -07:00
|
|
|
sbrowser.removeAttribute("origin");
|
2012-11-16 16:59:46 -08:00
|
|
|
sbrowser.setAttribute("src", "about:blank");
|
2012-10-23 17:09:59 -07:00
|
|
|
SocialFlyout.unload();
|
|
|
|
},
|
|
|
|
|
|
|
|
_unloadTimeoutId: 0,
|
|
|
|
|
2013-01-26 12:07:39 -08:00
|
|
|
setSidebarErrorMessage: function() {
|
2012-10-05 17:22:09 -07:00
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
2013-01-26 12:07:39 -08: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 13:10:04 -07:00
|
|
|
}
|
2012-07-18 11:40:05 -07:00
|
|
|
}
|
|
|
|
}
|
2013-03-26 16:15:59 -07:00
|
|
|
|
2013-09-04 10:01:38 -07:00
|
|
|
// this helper class is used by removable/customizable buttons to handle
|
|
|
|
// location persistence and insertion into palette and/or toolbars
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// To make this happen, on install we add a button id to the navbar currentset.
|
|
|
|
// On enabling the provider (happens just after install) we insert the button
|
|
|
|
// into the toolbar as well. The button is then persisted on restart (assuming
|
|
|
|
// it was not removed).
|
|
|
|
//
|
|
|
|
// When a provider is disabled, we do not remove the buttons from currentset.
|
|
|
|
// That way, if the provider is re-enabled during the same session, the buttons
|
|
|
|
// will reappear where they were before. When a provider is uninstalled, we make
|
|
|
|
// sure that the id is removed from currentset.
|
|
|
|
//
|
|
|
|
// On startup, we insert the buttons of any enabled provider into either the
|
|
|
|
// apropriate toolbar or the palette.
|
|
|
|
function ToolbarHelper(type, createButtonFn) {
|
|
|
|
this._createButton = createButtonFn;
|
|
|
|
this._type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarHelper.prototype = {
|
|
|
|
idFromOrgin: function(origin) {
|
|
|
|
return this._type + "-" + origin;
|
|
|
|
},
|
|
|
|
|
|
|
|
// find a button either in the document or the palette
|
|
|
|
_getExistingButton: function(id) {
|
|
|
|
let button = document.getElementById(id);
|
|
|
|
if (button)
|
|
|
|
return button;
|
|
|
|
let palette = document.getElementById("navigator-toolbox").palette;
|
|
|
|
let paletteItem = palette.firstChild;
|
|
|
|
while (paletteItem) {
|
|
|
|
if (paletteItem.id == id)
|
|
|
|
return paletteItem;
|
|
|
|
paletteItem = paletteItem.nextSibling;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
setPersistentPosition: function(id) {
|
|
|
|
// called when a provider is installed. add provider buttons to nav-bar
|
|
|
|
let toolbar = document.getElementById("nav-bar");
|
|
|
|
// first startups will not have a currentset attribute, always rely on
|
|
|
|
// currentSet since it will be derived from the defaultset in that case.
|
|
|
|
let currentset = toolbar.currentSet;
|
|
|
|
if (currentset == "__empty")
|
|
|
|
currentset = []
|
|
|
|
else
|
|
|
|
currentset = currentset.split(",");
|
|
|
|
if (currentset.indexOf(id) >= 0)
|
|
|
|
return;
|
|
|
|
// we do not set toolbar.currentSet since that will try to add the button,
|
|
|
|
// and we have not added it yet (happens on provider being enabled)
|
|
|
|
currentset.push(id);
|
|
|
|
toolbar.setAttribute("currentset", currentset.join(","));
|
|
|
|
document.persist(toolbar.id, "currentset");
|
|
|
|
},
|
|
|
|
|
|
|
|
removeProviderButton: function(origin) {
|
|
|
|
// this will remove the button from the palette or the toolbar
|
|
|
|
let button = this._getExistingButton(this.idFromOrgin(origin));
|
|
|
|
if (button)
|
|
|
|
button.parentNode.removeChild(button);
|
|
|
|
},
|
|
|
|
|
|
|
|
removePersistence: function(id) {
|
|
|
|
let persisted = document.querySelectorAll("*[currentset]");
|
|
|
|
for (let pent of persisted) {
|
|
|
|
// the button will have been removed, but left in the currentset attribute
|
|
|
|
// in case the user re-enables (e.g. undo in addon manager). So we only
|
|
|
|
// check the attribute here.
|
|
|
|
let currentset = pent.getAttribute("currentset").split(",");
|
|
|
|
|
|
|
|
let pos = currentset.indexOf(id);
|
|
|
|
if (pos >= 0) {
|
|
|
|
currentset.splice(pos, 1);
|
|
|
|
pent.setAttribute("currentset", currentset.join(","));
|
|
|
|
document.persist(pent.id, "currentset");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// if social is entirely disabled, we need to clear the palette, but leave
|
|
|
|
// the persisted id's in place
|
|
|
|
clearPalette: function() {
|
|
|
|
[this.removeProviderButton(p.origin) for (p of Social.providers)];
|
|
|
|
},
|
|
|
|
|
|
|
|
// should be called on startup of each window, otherwise the addon manager
|
|
|
|
// listener will handle new activations, or enable/disabling of a provider
|
|
|
|
// XXX we currently call more regularly, will fix during refactoring
|
|
|
|
populatePalette: function() {
|
|
|
|
if (!Social.enabled) {
|
|
|
|
this.clearPalette();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let persisted = document.querySelectorAll("*[currentset]");
|
|
|
|
let persistedById = {};
|
|
|
|
for (let pent of persisted) {
|
|
|
|
let pset = pent.getAttribute("currentset").split(',');
|
|
|
|
for (let id of pset)
|
|
|
|
persistedById[id] = pent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
let id = this.idFromOrgin(provider.origin);
|
|
|
|
if (this._getExistingButton(id))
|
2013-09-06 10:56:01 -07:00
|
|
|
continue;
|
2013-09-04 10:01:38 -07:00
|
|
|
let button = this._createButton(provider);
|
|
|
|
if (button && persistedById.hasOwnProperty(id)) {
|
|
|
|
let parent = persistedById[id];
|
|
|
|
let pset = persistedById[id].getAttribute("currentset").split(',');
|
|
|
|
let pi = pset.indexOf(id) + 1;
|
|
|
|
let next = document.getElementById(pset[pi]);
|
|
|
|
parent.insertItem(id, next, null, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SocialStatus = {
|
|
|
|
populateToolbarPalette: function() {
|
|
|
|
if (!Social.allowMultipleWorkers)
|
|
|
|
return;
|
|
|
|
this._toolbarHelper.populatePalette();
|
|
|
|
},
|
|
|
|
|
|
|
|
setPosition: function(origin) {
|
|
|
|
if (!Social.allowMultipleWorkers)
|
|
|
|
return;
|
|
|
|
// this is called during install, before the provider is enabled so we have
|
|
|
|
// to use the manifest rather than the provider instance as we do elsewhere.
|
|
|
|
let manifest = Social.getManifestByOrigin(origin);
|
|
|
|
if (!manifest.statusURL)
|
|
|
|
return;
|
|
|
|
let tbh = this._toolbarHelper;
|
|
|
|
tbh.setPersistentPosition(tbh.idFromOrgin(origin));
|
|
|
|
},
|
|
|
|
|
|
|
|
removePosition: function(origin) {
|
|
|
|
if (!Social.allowMultipleWorkers)
|
|
|
|
return;
|
|
|
|
let tbh = this._toolbarHelper;
|
|
|
|
tbh.removePersistence(tbh.idFromOrgin(origin));
|
|
|
|
},
|
|
|
|
|
|
|
|
removeProvider: function(origin) {
|
|
|
|
if (!Social.allowMultipleWorkers)
|
|
|
|
return;
|
2013-09-30 11:05:17 -07:00
|
|
|
this._removeFrame(origin);
|
2013-09-04 10:01:38 -07:00
|
|
|
this._toolbarHelper.removeProviderButton(origin);
|
|
|
|
},
|
|
|
|
|
2013-09-30 11:05:17 -07:00
|
|
|
_removeFrame: function(origin) {
|
|
|
|
let notificationFrameId = "social-status-" + origin;
|
|
|
|
let frame = document.getElementById(notificationFrameId);
|
|
|
|
if (frame) {
|
|
|
|
SharedFrame.forgetGroup(frame.id);
|
|
|
|
frame.parentNode.removeChild(frame);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-04 10:01:38 -07:00
|
|
|
get _toolbarHelper() {
|
|
|
|
delete this._toolbarHelper;
|
|
|
|
this._toolbarHelper = new ToolbarHelper("social-status-button", this._createButton.bind(this));
|
|
|
|
return this._toolbarHelper;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _dynamicResizer() {
|
|
|
|
delete this._dynamicResizer;
|
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
|
|
|
return this._dynamicResizer;
|
|
|
|
},
|
|
|
|
|
|
|
|
_createButton: function(provider) {
|
|
|
|
if (!provider.statusURL)
|
|
|
|
return null;
|
|
|
|
let palette = document.getElementById("navigator-toolbox").palette;
|
|
|
|
let button = document.createElement("toolbarbutton");
|
|
|
|
button.setAttribute("class", "toolbarbutton-1 social-status-button");
|
|
|
|
button.setAttribute("type", "badged");
|
|
|
|
button.setAttribute("removable", "true");
|
|
|
|
button.setAttribute("image", provider.iconURL);
|
|
|
|
button.setAttribute("label", provider.name);
|
|
|
|
button.setAttribute("tooltiptext", provider.name);
|
|
|
|
button.setAttribute("origin", provider.origin);
|
|
|
|
button.setAttribute("oncommand", "SocialStatus.showPopup(this);");
|
|
|
|
button.setAttribute("id", this._toolbarHelper.idFromOrgin(provider.origin));
|
|
|
|
palette.appendChild(button);
|
|
|
|
return button;
|
|
|
|
},
|
|
|
|
|
|
|
|
// status panels are one-per button per-process, we swap the docshells between
|
|
|
|
// windows when necessary
|
|
|
|
_attachNotificatonPanel: function(aButton, provider) {
|
|
|
|
let panel = document.getElementById("social-notification-panel");
|
|
|
|
panel.hidden = !SocialUI.enabled;
|
|
|
|
let notificationFrameId = "social-status-" + provider.origin;
|
|
|
|
let frame = document.getElementById(notificationFrameId);
|
|
|
|
|
|
|
|
if (!frame) {
|
|
|
|
frame = SharedFrame.createFrame(
|
|
|
|
notificationFrameId, /* frame name */
|
|
|
|
panel, /* parent */
|
|
|
|
{
|
|
|
|
"type": "content",
|
|
|
|
"mozbrowser": "true",
|
|
|
|
"class": "social-panel-frame",
|
|
|
|
"id": notificationFrameId,
|
|
|
|
"tooltip": "aHTMLTooltip",
|
|
|
|
|
|
|
|
// 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;",
|
|
|
|
|
|
|
|
"origin": provider.origin,
|
|
|
|
"src": provider.statusURL
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (frame.socialErrorListener)
|
|
|
|
frame.socialErrorListener.remove();
|
|
|
|
if (frame.docShell) {
|
|
|
|
frame.docShell.isActive = false;
|
|
|
|
Social.setErrorListener(frame, this.setPanelErrorMessage.bind(this));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frame.setAttribute("origin", provider.origin);
|
|
|
|
SharedFrame.updateURL(notificationFrameId, provider.statusURL);
|
|
|
|
}
|
|
|
|
aButton.setAttribute("notificationFrameId", notificationFrameId);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateNotification: function(origin) {
|
|
|
|
if (!Social.allowMultipleWorkers)
|
|
|
|
return;
|
|
|
|
let provider = Social._getProviderFromOrigin(origin);
|
|
|
|
let button = document.getElementById(this._toolbarHelper.idFromOrgin(provider.origin));
|
|
|
|
if (button) {
|
|
|
|
// we only grab the first notification, ignore all others
|
|
|
|
let icons = provider.ambientNotificationIcons;
|
|
|
|
let iconNames = Object.keys(icons);
|
|
|
|
let notif = icons[iconNames[0]];
|
|
|
|
if (!notif) {
|
|
|
|
button.setAttribute("badge", "");
|
|
|
|
button.setAttribute("aria-label", "");
|
|
|
|
button.setAttribute("tooltiptext", "");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
button.style.listStyleImage = "url(" + notif.iconURL || provider.iconURL + ")";
|
|
|
|
button.setAttribute("tooltiptext", notif.label);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showPopup: function(aToolbarButton) {
|
|
|
|
if (!Social.allowMultipleWorkers)
|
|
|
|
return;
|
|
|
|
// attach our notification panel if necessary
|
|
|
|
let origin = aToolbarButton.getAttribute("origin");
|
|
|
|
let provider = Social._getProviderFromOrigin(origin);
|
|
|
|
this._attachNotificatonPanel(aToolbarButton, provider);
|
|
|
|
|
|
|
|
let panel = document.getElementById("social-notification-panel");
|
|
|
|
let notificationFrameId = aToolbarButton.getAttribute("notificationFrameId");
|
|
|
|
let notificationFrame = document.getElementById(notificationFrameId);
|
|
|
|
|
|
|
|
let wasAlive = SharedFrame.isGroupAlive(notificationFrameId);
|
|
|
|
SharedFrame.setOwner(notificationFrameId, notificationFrame);
|
|
|
|
|
|
|
|
// Clear dimensions on all browsers so the panel size will
|
|
|
|
// only use the selected browser.
|
|
|
|
let frameIter = panel.firstElementChild;
|
|
|
|
while (frameIter) {
|
|
|
|
frameIter.collapsed = (frameIter != notificationFrame);
|
|
|
|
frameIter = frameIter.nextElementSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchPanelEvent(name) {
|
|
|
|
let evt = notificationFrame.contentDocument.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent(name, true, true, {});
|
|
|
|
notificationFrame.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
let dynamicResizer = this._dynamicResizer;
|
|
|
|
panel.addEventListener("popuphidden", function onpopuphiding() {
|
|
|
|
panel.removeEventListener("popuphidden", onpopuphiding);
|
|
|
|
aToolbarButton.removeAttribute("open");
|
|
|
|
dynamicResizer.stop();
|
|
|
|
notificationFrame.docShell.isActive = false;
|
|
|
|
dispatchPanelEvent("socialFrameHide");
|
|
|
|
});
|
|
|
|
|
|
|
|
panel.addEventListener("popupshown", function onpopupshown() {
|
|
|
|
panel.removeEventListener("popupshown", onpopupshown);
|
|
|
|
// 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");
|
|
|
|
notificationFrame.docShell.isActive = true;
|
|
|
|
notificationFrame.docShell.isAppTab = true;
|
|
|
|
if (notificationFrame.contentDocument.readyState == "complete" && wasAlive) {
|
|
|
|
dynamicResizer.start(panel, notificationFrame);
|
|
|
|
dispatchPanelEvent("socialFrameShow");
|
|
|
|
} else {
|
|
|
|
// first time load, wait for load and dispatch after load
|
|
|
|
notificationFrame.addEventListener("load", function panelBrowserOnload(e) {
|
|
|
|
notificationFrame.removeEventListener("load", panelBrowserOnload, true);
|
|
|
|
dynamicResizer.start(panel, notificationFrame);
|
|
|
|
dispatchPanelEvent("socialFrameShow");
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let navBar = document.getElementById("nav-bar");
|
|
|
|
let anchor = navBar.getAttribute("mode") == "text" ?
|
|
|
|
document.getAnonymousElementByAttribute(aToolbarButton, "class", "toolbarbutton-text") :
|
|
|
|
document.getAnonymousElementByAttribute(aToolbarButton, "class", "toolbarbutton-badge-container");
|
|
|
|
// Bug 849216 - open the popup in a setTimeout so we avoid the auto-rollup
|
|
|
|
// handling from preventing it being opened in some cases.
|
|
|
|
setTimeout(function() {
|
|
|
|
panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
setPanelErrorMessage: function(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);
|
|
|
|
let panel = aNotificationFrame.parentNode;
|
|
|
|
sizeSocialPanelToContent(panel, aNotificationFrame);
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-09-06 10:56:01 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SocialMarks
|
|
|
|
*
|
|
|
|
* Handles updates to toolbox and signals all buttons to update when necessary.
|
|
|
|
*/
|
|
|
|
SocialMarks = {
|
|
|
|
update: function() {
|
|
|
|
// signal each button to update itself
|
|
|
|
let currentButtons = document.querySelectorAll('toolbarbutton[type="socialmark"]');
|
|
|
|
for (let elt of currentButtons)
|
|
|
|
elt.update();
|
|
|
|
},
|
|
|
|
|
|
|
|
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.
|
|
|
|
let tbh = this._toolbarHelper;
|
|
|
|
return [p for (p of Social.providers) if (p.markURL &&
|
|
|
|
document.getElementById(tbh.idFromOrgin(p.origin)))];
|
|
|
|
},
|
|
|
|
|
|
|
|
populateContextMenu: function() {
|
|
|
|
// only show a selection if enabled and there is more than one
|
|
|
|
let providers = this.getProviders();
|
|
|
|
|
|
|
|
// remove all previous entries by class
|
|
|
|
let menus = [m for (m of document.getElementsByClassName("context-socialmarks"))];
|
|
|
|
[m.parentNode.removeChild(m) for (m of menus)];
|
|
|
|
|
|
|
|
let contextMenus = [
|
|
|
|
{
|
|
|
|
type: "link",
|
|
|
|
id: "context-marklinkMenu",
|
2013-09-11 06:51:03 -07:00
|
|
|
label: "social.marklinkMenu.label"
|
2013-09-06 10:56:01 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "page",
|
|
|
|
id: "context-markpageMenu",
|
2013-09-11 06:51:03 -07:00
|
|
|
label: "social.markpageMenu.label"
|
2013-09-06 10:56:01 -07:00
|
|
|
}
|
|
|
|
];
|
|
|
|
for (let cfg of contextMenus) {
|
|
|
|
this._populateContextPopup(cfg, providers);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
|
|
|
setPosition: function(origin) {
|
|
|
|
// this is called during install, before the provider is enabled so we have
|
|
|
|
// to use the manifest rather than the provider instance as we do elsewhere.
|
|
|
|
let manifest = Social.getManifestByOrigin(origin);
|
|
|
|
if (!manifest.markURL)
|
|
|
|
return;
|
|
|
|
let tbh = this._toolbarHelper;
|
|
|
|
tbh.setPersistentPosition(tbh.idFromOrgin(origin));
|
|
|
|
},
|
|
|
|
|
|
|
|
removePosition: function(origin) {
|
|
|
|
let tbh = this._toolbarHelper;
|
|
|
|
tbh.removePersistence(tbh.idFromOrgin(origin));
|
|
|
|
},
|
|
|
|
|
|
|
|
removeProvider: function(origin) {
|
|
|
|
this._toolbarHelper.removeProviderButton(origin);
|
|
|
|
},
|
|
|
|
|
|
|
|
get _toolbarHelper() {
|
|
|
|
delete this._toolbarHelper;
|
|
|
|
this._toolbarHelper = new ToolbarHelper("social-mark-button", this._createButton.bind(this));
|
|
|
|
return this._toolbarHelper;
|
|
|
|
},
|
|
|
|
|
|
|
|
_createButton: function(provider) {
|
|
|
|
if (!provider.markURL)
|
|
|
|
return null;
|
|
|
|
let palette = document.getElementById("navigator-toolbox").palette;
|
|
|
|
let button = document.createElement("toolbarbutton");
|
|
|
|
button.setAttribute("type", "socialmark");
|
|
|
|
button.setAttribute("class", "toolbarbutton-1 social-mark-button");
|
|
|
|
button.style.listStyleImage = "url(" + provider.iconURL + ")";
|
|
|
|
button.setAttribute("origin", provider.origin);
|
|
|
|
button.setAttribute("id", this._toolbarHelper.idFromOrgin(provider.origin));
|
|
|
|
palette.appendChild(button);
|
|
|
|
return button
|
|
|
|
},
|
|
|
|
|
|
|
|
markLink: function(aOrigin, aUrl) {
|
|
|
|
// find the button for this provider, and open it
|
|
|
|
let id = this._toolbarHelper.idFromOrgin(aOrigin);
|
|
|
|
document.getElementById(id).markLink(aUrl);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:15:59 -07:00
|
|
|
})();
|