|
1 # -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 # This Source Code Form is subject to the terms of the Mozilla Public |
|
3 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
5 |
|
6 let WebrtcIndicator = { |
|
7 init: function () { |
|
8 let temp = {}; |
|
9 Cu.import("resource:///modules/webrtcUI.jsm", temp); |
|
10 this.UIModule = temp.webrtcUI; |
|
11 |
|
12 this.updateButton(); |
|
13 }, |
|
14 |
|
15 get button() { |
|
16 delete this.button; |
|
17 return this.button = document.getElementById("webrtc-status-button"); |
|
18 }, |
|
19 |
|
20 updateButton: function () { |
|
21 this.button.hidden = !this.UIModule.showGlobalIndicator; |
|
22 }, |
|
23 |
|
24 fillPopup: function (aPopup) { |
|
25 this._menuitemData = new WeakMap; |
|
26 for (let streamData of this.UIModule.activeStreams) { |
|
27 let pageURI = Services.io.newURI(streamData.uri, null, null); |
|
28 let menuitem = document.createElement("menuitem"); |
|
29 menuitem.setAttribute("class", "menuitem-iconic"); |
|
30 menuitem.setAttribute("label", streamData.browser.contentTitle || streamData.uri); |
|
31 menuitem.setAttribute("tooltiptext", streamData.uri); |
|
32 PlacesUtils.favicons.getFaviconURLForPage(pageURI, function (aURI) { |
|
33 if (aURI) { |
|
34 let iconURL = PlacesUtils.favicons.getFaviconLinkForIcon(aURI).spec; |
|
35 menuitem.setAttribute("image", iconURL); |
|
36 } |
|
37 }); |
|
38 |
|
39 this._menuitemData.set(menuitem, streamData); |
|
40 |
|
41 aPopup.appendChild(menuitem); |
|
42 } |
|
43 }, |
|
44 |
|
45 clearPopup: function (aPopup) { |
|
46 while (aPopup.lastChild) |
|
47 aPopup.removeChild(aPopup.lastChild); |
|
48 }, |
|
49 |
|
50 menuCommand: function (aMenuitem) { |
|
51 let streamData = this._menuitemData.get(aMenuitem); |
|
52 if (!streamData) |
|
53 return; |
|
54 |
|
55 let browserWindow = streamData.browser.ownerDocument.defaultView; |
|
56 if (streamData.tab) { |
|
57 browserWindow.gBrowser.selectedTab = streamData.tab; |
|
58 } else { |
|
59 streamData.browser.focus(); |
|
60 } |
|
61 browserWindow.focus(); |
|
62 PopupNotifications.getNotification("webRTC-sharingDevices", |
|
63 streamData.browser).reshow(); |
|
64 } |
|
65 } |