|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 let Cu = Components.utils; |
|
8 let Ci = Components.interfaces; |
|
9 |
|
10 Cu.import("resource:///modules/tabview/utils.jsm"); |
|
11 |
|
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); |
|
17 }); |
|
18 |
|
19 // ---------- |
|
20 // WindowEventHandler |
|
21 // |
|
22 // Handles events dispatched by the content window. |
|
23 let WindowEventHandler = { |
|
24 // ---------- |
|
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. |
|
31 if (!event.isTrusted) |
|
32 return; |
|
33 |
|
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"); |
|
38 }, |
|
39 |
|
40 // ---------- |
|
41 // Function: onMozAfterPaint |
|
42 // Sends an asynchronous message when the "onMozAfterPaint" event |
|
43 // is fired. |
|
44 onMozAfterPaint: function WEH_onMozAfterPaint(event) { |
|
45 if (event.clientRects.length > 0) { |
|
46 sendAsyncMessage("Panorama:MozAfterPaint"); |
|
47 } |
|
48 } |
|
49 }; |
|
50 |
|
51 // add event listeners |
|
52 addEventListener("DOMWillOpenModalDialog", WindowEventHandler.onDOMWillOpenModalDialog, false); |
|
53 addEventListener("MozAfterPaint", WindowEventHandler.onMozAfterPaint, false); |
|
54 |
|
55 // ---------- |
|
56 // WindowMessageHandler |
|
57 // |
|
58 // Handles messages sent by the chrome process. |
|
59 let WindowMessageHandler = { |
|
60 // ---------- |
|
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); |
|
66 |
|
67 sendAsyncMessage(cx.name, {isLoaded: isLoaded}); |
|
68 }, |
|
69 |
|
70 // ---------- |
|
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); |
|
75 |
|
76 sendAsyncMessage(cx.name, {isImageDocument: isImageDocument}); |
|
77 } |
|
78 }; |
|
79 |
|
80 // add message listeners |
|
81 addMessageListener("Panorama:isDocumentLoaded", WindowMessageHandler.isDocumentLoaded); |
|
82 addMessageListener("Panorama:isImageDocument", WindowMessageHandler.isImageDocument); |
|
83 |