Bug 1250534: introduce a ChatboxClosed event that fires when a chatbox is closed in attached and detached mode. r=Standard8

This commit is contained in:
Mike de Boer 2016-03-09 11:29:25 +01:00
Родитель 2c116e74fa
Коммит d08231b4e1
2 изменённых файлов: 45 добавлений и 20 удалений

Просмотреть файл

@ -250,6 +250,9 @@
this.chatbar.remove(this);
else
window.close();
if (!this.swappingWindows)
this.dispatchEvent(new CustomEvent("ChatboxClosed"));
]]></body>
</method>
@ -285,6 +288,7 @@
this.swapDocShells(cb);
chatbar.focus();
this.swappingWindows = true;
this.close();
// chatboxForURL is a map of URL -> chatbox used to avoid opening
@ -796,14 +800,27 @@
aChatbox.setDecorationAttributes(otherChatbox);
aChatbox.swapDocShells(otherChatbox);
aChatbox.swappingWindows = true;
aChatbox.close();
chatbar.chatboxForURL.set(aChatbox.src, Cu.getWeakReference(otherChatbox));
let url = aChatbox.src;
chatbar.chatboxForURL.set(url, Cu.getWeakReference(otherChatbox));
// All processing is done, now we can fire the event.
otherChatbox.content.messageManager.sendAsyncMessage("Social:CustomEvent", {
name: "socialFrameDetached"
});
Services.obs.addObserver(function onDOMWindowClosed(subject) {
if (subject !== otherWin)
return;
Services.obs.removeObserver(onDOMWindowClosed, "domwindowclosed");
chatbar.chatboxForURL.delete(url);
if (!otherChatbox.swappingWindows)
otherChatbox.dispatchEvent(new CustomEvent("ChatboxClosed"));
}, "domwindowclosed", false);
deferred.resolve(otherChatbox);
}, true);
return deferred.promise;

Просмотреть файл

@ -1013,24 +1013,6 @@ var MozLoopServiceInternal = {
mm.sendAsyncMessage("Social:HookWindowCloseForPanelClose");
messageName = "Social:DOMWindowClose";
mm.addMessageListener(messageName, listeners[messageName] = () => {
// Remove message listeners.
for (let name of Object.getOwnPropertyNames(listeners)) {
mm.removeMessageListener(name, listeners[name]);
}
listeners = {};
windowCloseCallback();
if (conversationWindowData.type == "room") {
// NOTE: if you add something here, please also consider if something
// needs to be done on the content side as well (e.g.
// activeRoomStore#windowUnload).
LoopAPI.sendMessageToHandler({
name: "HangupNow",
data: [conversationWindowData.roomToken, windowId]
});
}
chatbox.close();
});
@ -1065,6 +1047,28 @@ var MozLoopServiceInternal = {
}
});
let closeListener = function() {
this.removeEventListener("ChatboxClosed", closeListener);
// Remove message listeners.
for (let name of Object.getOwnPropertyNames(listeners)) {
mm.removeMessageListener(name, listeners[name]);
}
listeners = {};
windowCloseCallback();
if (conversationWindowData.type == "room") {
// NOTE: if you add something here, please also consider if something
// needs to be done on the content side as well (e.g.
// activeRoomStore#windowUnload).
LoopAPI.sendMessageToHandler({
name: "HangupNow",
data: [conversationWindowData.roomToken, windowId]
});
}
};
// When a chat window is attached or detached, the docShells hosting
// about:loopconverstation is swapped to the newly created chat window.
// (Be it inside a popup or back inside a chatbox element attached to the
@ -1074,18 +1078,22 @@ var MozLoopServiceInternal = {
// the new messageManager. This is not a bug in swapDocShells, merely
// a design decision.
chatbox.content.addEventListener("SwapDocShells", function swapped(ev) {
chatbox.content.removeEventListener("SwapDocShells", swapped);
this.removeEventListener("SwapDocShells", swapped);
this.removeEventListener("ChatboxClosed", closeListener);
let otherBrowser = ev.detail;
chatbox = otherBrowser.ownerDocument.getBindingParent(otherBrowser);
mm = otherBrowser.messageManager;
otherBrowser.addEventListener("SwapDocShells", swapped);
chatbox.addEventListener("ChatboxClosed", closeListener);
for (let name of Object.getOwnPropertyNames(listeners)) {
mm.addMessageListener(name, listeners[name]);
}
});
chatbox.addEventListener("ChatboxClosed", closeListener);
UITour.notify("Loop:ChatWindowOpened");
resolve(windowId);
};