michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: let Cu = Components.utils; michael@0: let Ci = Components.interfaces; michael@0: michael@0: Cu.import("resource:///modules/tabview/utils.jsm"); michael@0: michael@0: // Bug 671101 - directly using webProgress in this context michael@0: // causes docShells to leak michael@0: this.__defineGetter__("webProgress", function () { michael@0: let ifaceReq = docShell.QueryInterface(Ci.nsIInterfaceRequestor); michael@0: return ifaceReq.getInterface(Ci.nsIWebProgress); michael@0: }); michael@0: michael@0: // ---------- michael@0: // WindowEventHandler michael@0: // michael@0: // Handles events dispatched by the content window. michael@0: let WindowEventHandler = { michael@0: // ---------- michael@0: // Function: onDOMWillOpenModalDialog michael@0: // Sends a synchronous message when the "onDOMWillOpenModalDialog" event michael@0: // is fired right before a modal dialog will be opened by the current page. michael@0: onDOMWillOpenModalDialog: function WEH_onDOMWillOpenModalDialog(event) { michael@0: // (event.isTrusted == true) when the event is generated by a user action michael@0: // and does not originate from a script. michael@0: if (!event.isTrusted) michael@0: return; michael@0: michael@0: // we're intentionally sending a synchronous message to handle this event michael@0: // as quick as possible, switch the selected tab and hide the tabview michael@0: // before the modal dialog is shown michael@0: sendSyncMessage("Panorama:DOMWillOpenModalDialog"); michael@0: }, michael@0: michael@0: // ---------- michael@0: // Function: onMozAfterPaint michael@0: // Sends an asynchronous message when the "onMozAfterPaint" event michael@0: // is fired. michael@0: onMozAfterPaint: function WEH_onMozAfterPaint(event) { michael@0: if (event.clientRects.length > 0) { michael@0: sendAsyncMessage("Panorama:MozAfterPaint"); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: // add event listeners michael@0: addEventListener("DOMWillOpenModalDialog", WindowEventHandler.onDOMWillOpenModalDialog, false); michael@0: addEventListener("MozAfterPaint", WindowEventHandler.onMozAfterPaint, false); michael@0: michael@0: // ---------- michael@0: // WindowMessageHandler michael@0: // michael@0: // Handles messages sent by the chrome process. michael@0: let WindowMessageHandler = { michael@0: // ---------- michael@0: // Function: isDocumentLoaded michael@0: // Checks if the currently active document is loaded. michael@0: isDocumentLoaded: function WMH_isDocumentLoaded(cx) { michael@0: let isLoaded = (content.document.readyState != "uninitialized" && michael@0: !webProgress.isLoadingDocument); michael@0: michael@0: sendAsyncMessage(cx.name, {isLoaded: isLoaded}); michael@0: }, michael@0: michael@0: // ---------- michael@0: // Function: isImageDocument michael@0: // Checks if the currently active document is an image document or not. michael@0: isImageDocument: function WMH_isImageDocument(cx) { michael@0: let isImageDocument = (content.document instanceof Ci.nsIImageDocument); michael@0: michael@0: sendAsyncMessage(cx.name, {isImageDocument: isImageDocument}); michael@0: } michael@0: }; michael@0: michael@0: // add message listeners michael@0: addMessageListener("Panorama:isDocumentLoaded", WindowMessageHandler.isDocumentLoaded); michael@0: addMessageListener("Panorama:isImageDocument", WindowMessageHandler.isImageDocument); michael@0: