1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // the "exported" symbols
8 XPCOMUtils.defineLazyModuleGetter(this, "injectLoopAPI", "resource:///modules/loop/MozLoopAPI.jsm");
9 XPCOMUtils.defineLazyModuleGetter(this, "MozLoopService", "resource:///modules/loop/MozLoopService.jsm");
10 XPCOMUtils.defineLazyModuleGetter(this, "PanelFrame", "resource:///modules/PanelFrame.jsm");
17 delete this.toolbarButton;
18 return this.toolbarButton = CustomizableUI.getWidget("loop-button-throttled").forWindow(window);
22 * Opens the panel for Loop and sizes it appropriately.
24 * @param {event} event The event opening the panel, used to anchor
25 * the panel to the button which triggers it.
27 openCallPanel: function(event) {
28 let callback = iframe => {
29 iframe.addEventListener("DOMContentLoaded", function documentDOMLoaded() {
30 iframe.removeEventListener("DOMContentLoaded", documentDOMLoaded, true);
31 injectLoopAPI(iframe.contentWindow);
35 // Used to clear the temporary "login" state from the button.
36 Services.obs.notifyObservers(null, "loop-status-changed", null);
38 PanelFrame.showPopup(window, event.target, "loop", null,
39 "about:looppanel", null, callback);
43 * Triggers the initialization of the loop service. Called by
47 // Add observer notifications before the service is initialized
48 Services.obs.addObserver(this, "loop-status-changed", false);
50 MozLoopService.initialize();
51 this.updateToolbarState();
55 Services.obs.removeObserver(this, "loop-status-changed");
58 // Implements nsIObserver
59 observe: function(subject, topic, data) {
60 if (topic != "loop-status-changed") {
63 this.updateToolbarState(data);
67 * Updates the toolbar/menu-button state to reflect Loop status.
69 * @param {string} [aReason] Some states are only shown if
70 * a related reason is provided.
72 * aReason="login": Used after a login is completed
73 * successfully. This is used so the state can be
74 * temporarily shown until the next state change.
76 updateToolbarState: function(aReason = null) {
77 let toolbarButton = this.toolbarButton;
78 if (!toolbarButton || !toolbarButton.node) {
83 if (MozLoopService.errors.size) {
85 } else if (aReason == "login" && MozLoopService.userProfile) {
87 } else if (MozLoopService.doNotDisturb) {
90 toolbarButton.node.setAttribute("state", state);