diff --git a/addon/bootstrap.js b/addon/bootstrap.js index 33c3d51..1fe8a4c 100644 --- a/addon/bootstrap.js +++ b/addon/bootstrap.js @@ -57,6 +57,49 @@ let webrtcbrowser = { } }, + _detachToTabListener: function webrtcbrowser__detachToTabListener(aEvent) { + let currentBrowser = this.selectedChat.iframe; + let gBrowser = this.ownerDocument.getElementById("content"); + + // browser.swapDocShells expects a browser, not an iframe, so simulate + // the missing methods. + currentBrowser.getTabBrowser = function() { return null; }; + currentBrowser.detachFormFill = function() {}; + currentBrowser.attachFormFill = function() {}; + + let tab = gBrowser.loadOneTab("about:blank", null, null, null, false); + gBrowser.swapNewTabWithBrowser(tab, currentBrowser); + this.selectedChat.close(); + aEvent.preventDefault(); // This lets the emitter of the event know it's been handled. + gBrowser.setTabTitle(tab); + }, + + listenToDetachToTabEvents: function webrtcbrowser_listenToDetachToTabEvents() { + var windows = Services.ww.getWindowEnumerator(); + while (windows.hasMoreElements()) { + var window = windows.getNext().QueryInterface(Components.interfaces.nsIDOMWindow); + if (window.location.href == "chrome://browser/content/browser.xul") { + window.document.getElementById("pinnedchats") + .addEventListener("detachToTab", + webrtcbrowser._detachToTabListener, + false, true); + } + } + }, + + unlistenToDetachToTabEvents: function webrtcbrowser_unlistenToDetachToTabEvents() { + var windows = Services.ww.getWindowEnumerator(); + while (windows.hasMoreElements()) { + var window = windows.getNext().QueryInterface(Components.interfaces.nsIDOMWindow); + if (window.location.href == "chrome://browser/content/browser.xul") { + window.document.getElementById("pinnedchats") + .removeEventListener("detachToTab", + webrtcbrowser._detachToTabListener, + false, true); + } + } + }, + setWidths: function webrtcbrowser_setWidths() { try { var windows = Services.ww.getWindowEnumerator(); @@ -122,10 +165,12 @@ let webrtcbrowser = { Services.obs.addObserver(this, "social:profile-changed", false); this.setWidths(); this.setStyle(); + this.listenToDetachToTabEvents(); }, uninit: function webrtcbrowser_uninit() { this.unloadStyle(); + this.unlistenToDetachToTabEvents(); Services.obs.removeObserver(this, "social:profile-changed"); }, diff --git a/addon/install.rdf b/addon/install.rdf index fa6012b..aa4a100 100644 --- a/addon/install.rdf +++ b/addon/install.rdf @@ -3,7 +3,7 @@ webrtc-demo@mozillalabs.com WebRTC Demo Improvements - 0.8 + 0.9 Adds default variables for webrtc and some extra features true https://webrtc-demo.vcap.mozillalabs.com/update.rdf diff --git a/static/sidebar.js b/static/sidebar.js index 467bc18..d33ded4 100644 --- a/static/sidebar.js +++ b/static/sidebar.js @@ -198,46 +198,63 @@ function setupFileSharing(win, dc, target) { } } +function finishDetachTab(aWindow) { + var doc = aWindow.document; + var localVideo = doc.getElementById("localVideo"); + var video = doc.getElementById("remoteVideo"); + video.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 1; background: black;"); + + var resizeVideo = function() { + var height = aWindow.innerHeight; + var width = aWindow.innerWidth; + + video.setAttribute("width", width); + video.setAttribute("height", height); + + localVideo.setAttribute("width", "108"); + localVideo.setAttribute("height", "81"); + localVideo.setAttribute("style", "position: fixed; z-index: 2;"); + localVideo.style.top = (height - 81) + "px"; + localVideo.style.left = (width - 108) + "px"; + }; + resizeVideo(); + aWindow.addEventListener("resize", resizeVideo); + + var button = doc.getElementById("fullTab"); + button.onclick = function() { + doc.getElementById("video").mozRequestFullScreen(); + }; + button.textContent = "Full screen"; +} + function setupExpandHandler(win) { win.document.getElementById("fullTab").onclick = function() { - var tab = win.open(win.location); - tab.addEventListener("DOMContentLoaded", function() { - tab.document.title = win.document.title; + var doc = win.document; + var event = doc.createEvent("UIEvents"); + event.initUIEvent("detachToTab", true, true, win, 0); + win.dispatchEvent(event); - var video = win.document.getElementById("remoteVideo"); - var newVideo = tab.document.getElementById("remoteVideo"); - newVideo.mozSrcObject = video.mozSrcObject; - newVideo.play(); - newVideo.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 1; background: black;"); + if (!event.defaultPrevented) { + // The add-on isn't installed, fallback to opening a new tab and + // keeping the floating window around. + var tab = win.open(win.location); + tab.addEventListener("DOMContentLoaded", function() { + tab.document.title = win.document.title; - var localVideo = win.document.getElementById("localVideo"); - var newLocalVideo = tab.document.getElementById("localVideo"); - newLocalVideo.mozSrcObject = localVideo.mozSrcObject; - newLocalVideo.play(); + var video = doc.getElementById("remoteVideo"); + var newVideo = tab.document.getElementById("remoteVideo"); + newVideo.mozSrcObject = video.mozSrcObject; + newVideo.play(); - var resizeVideo = function() { - var height = tab.innerHeight; - var width = tab.innerWidth; - var doc = tab.document; - - newVideo.setAttribute("width", width); - newVideo.setAttribute("height", height); - - newLocalVideo.setAttribute("width", "108"); - newLocalVideo.setAttribute("height", "81"); - newLocalVideo.setAttribute("style", "position: fixed; z-index: 2;"); - newLocalVideo.style.top = (height - 81) + "px"; - newLocalVideo.style.left = (width - 108) + "px"; - }; - resizeVideo(); - tab.addEventListener("resize", resizeVideo); - - var button = tab.document.getElementById("fullTab"); - button.onclick = function() { - tab.document.getElementById("video").mozRequestFullScreen(); - }; - button.textContent = "Full screen"; - }); + var localVideo = doc.getElementById("localVideo"); + var newLocalVideo = tab.document.getElementById("localVideo"); + newLocalVideo.mozSrcObject = localVideo.mozSrcObject; + newLocalVideo.play(); + finishDetachTab(tab); + }); + } + else + finishDetachTab(doc.defaultView); }; } diff --git a/static/update.rdf b/static/update.rdf index d6e1cb8..0c88b39 100644 --- a/static/update.rdf +++ b/static/update.rdf @@ -10,7 +10,7 @@ - 0.8 + 0.9 {ec8030f7-c20a-464f-9b0e-13a3a9e97384} @@ -18,7 +18,7 @@ 21.0a1 https://webrtc-demo.vcap.mozillalabs.com/webrtc.xpi https://webrtc-demo.vcap.mozillalabs.com/update.txt - sha256:012683881177e3d640228e1cd48064db9a6a0853a89507255307854599810d83 + sha256:97dabc30764643790b1c523f5a3cb0594433b1b5f4503d2e566ba20235f0ee02 diff --git a/static/webrtc.xpi b/static/webrtc.xpi index dfe8af1..8f0dc9d 100644 Binary files a/static/webrtc.xpi and b/static/webrtc.xpi differ