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 file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 let Cu = Components.utils;
8 let Ci = Components.interfaces;
10 Cu.import("resource:///modules/tabview/utils.jsm");
12 // Bug 671101 - directly using webProgress in this context
13 // causes docShells to leak
14 this.__defineGetter__("webProgress", function () {
15 let ifaceReq = docShell.QueryInterface(Ci.nsIInterfaceRequestor);
16 return ifaceReq.getInterface(Ci.nsIWebProgress);
22 // Handles events dispatched by the content window.
23 let WindowEventHandler = {
25 // Function: onDOMWillOpenModalDialog
26 // Sends a synchronous message when the "onDOMWillOpenModalDialog" event
27 // is fired right before a modal dialog will be opened by the current page.
28 onDOMWillOpenModalDialog: function WEH_onDOMWillOpenModalDialog(event) {
29 // (event.isTrusted == true) when the event is generated by a user action
30 // and does not originate from a script.
34 // we're intentionally sending a synchronous message to handle this event
35 // as quick as possible, switch the selected tab and hide the tabview
36 // before the modal dialog is shown
37 sendSyncMessage("Panorama:DOMWillOpenModalDialog");
41 // Function: onMozAfterPaint
42 // Sends an asynchronous message when the "onMozAfterPaint" event
44 onMozAfterPaint: function WEH_onMozAfterPaint(event) {
45 if (event.clientRects.length > 0) {
46 sendAsyncMessage("Panorama:MozAfterPaint");
51 // add event listeners
52 addEventListener("DOMWillOpenModalDialog", WindowEventHandler.onDOMWillOpenModalDialog, false);
53 addEventListener("MozAfterPaint", WindowEventHandler.onMozAfterPaint, false);
56 // WindowMessageHandler
58 // Handles messages sent by the chrome process.
59 let WindowMessageHandler = {
61 // Function: isDocumentLoaded
62 // Checks if the currently active document is loaded.
63 isDocumentLoaded: function WMH_isDocumentLoaded(cx) {
64 let isLoaded = (content.document.readyState != "uninitialized" &&
65 !webProgress.isLoadingDocument);
67 sendAsyncMessage(cx.name, {isLoaded: isLoaded});
71 // Function: isImageDocument
72 // Checks if the currently active document is an image document or not.
73 isImageDocument: function WMH_isImageDocument(cx) {
74 let isImageDocument = (content.document instanceof Ci.nsIImageDocument);
76 sendAsyncMessage(cx.name, {isImageDocument: isImageDocument});
80 // add message listeners
81 addMessageListener("Panorama:isDocumentLoaded", WindowMessageHandler.isDocumentLoaded);
82 addMessageListener("Panorama:isImageDocument", WindowMessageHandler.isImageDocument);