Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | let Cu = Components.utils; |
michael@0 | 8 | let Ci = Components.interfaces; |
michael@0 | 9 | |
michael@0 | 10 | Cu.import("resource:///modules/tabview/utils.jsm"); |
michael@0 | 11 | |
michael@0 | 12 | // Bug 671101 - directly using webProgress in this context |
michael@0 | 13 | // causes docShells to leak |
michael@0 | 14 | this.__defineGetter__("webProgress", function () { |
michael@0 | 15 | let ifaceReq = docShell.QueryInterface(Ci.nsIInterfaceRequestor); |
michael@0 | 16 | return ifaceReq.getInterface(Ci.nsIWebProgress); |
michael@0 | 17 | }); |
michael@0 | 18 | |
michael@0 | 19 | // ---------- |
michael@0 | 20 | // WindowEventHandler |
michael@0 | 21 | // |
michael@0 | 22 | // Handles events dispatched by the content window. |
michael@0 | 23 | let WindowEventHandler = { |
michael@0 | 24 | // ---------- |
michael@0 | 25 | // Function: onDOMWillOpenModalDialog |
michael@0 | 26 | // Sends a synchronous message when the "onDOMWillOpenModalDialog" event |
michael@0 | 27 | // is fired right before a modal dialog will be opened by the current page. |
michael@0 | 28 | onDOMWillOpenModalDialog: function WEH_onDOMWillOpenModalDialog(event) { |
michael@0 | 29 | // (event.isTrusted == true) when the event is generated by a user action |
michael@0 | 30 | // and does not originate from a script. |
michael@0 | 31 | if (!event.isTrusted) |
michael@0 | 32 | return; |
michael@0 | 33 | |
michael@0 | 34 | // we're intentionally sending a synchronous message to handle this event |
michael@0 | 35 | // as quick as possible, switch the selected tab and hide the tabview |
michael@0 | 36 | // before the modal dialog is shown |
michael@0 | 37 | sendSyncMessage("Panorama:DOMWillOpenModalDialog"); |
michael@0 | 38 | }, |
michael@0 | 39 | |
michael@0 | 40 | // ---------- |
michael@0 | 41 | // Function: onMozAfterPaint |
michael@0 | 42 | // Sends an asynchronous message when the "onMozAfterPaint" event |
michael@0 | 43 | // is fired. |
michael@0 | 44 | onMozAfterPaint: function WEH_onMozAfterPaint(event) { |
michael@0 | 45 | if (event.clientRects.length > 0) { |
michael@0 | 46 | sendAsyncMessage("Panorama:MozAfterPaint"); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | // add event listeners |
michael@0 | 52 | addEventListener("DOMWillOpenModalDialog", WindowEventHandler.onDOMWillOpenModalDialog, false); |
michael@0 | 53 | addEventListener("MozAfterPaint", WindowEventHandler.onMozAfterPaint, false); |
michael@0 | 54 | |
michael@0 | 55 | // ---------- |
michael@0 | 56 | // WindowMessageHandler |
michael@0 | 57 | // |
michael@0 | 58 | // Handles messages sent by the chrome process. |
michael@0 | 59 | let WindowMessageHandler = { |
michael@0 | 60 | // ---------- |
michael@0 | 61 | // Function: isDocumentLoaded |
michael@0 | 62 | // Checks if the currently active document is loaded. |
michael@0 | 63 | isDocumentLoaded: function WMH_isDocumentLoaded(cx) { |
michael@0 | 64 | let isLoaded = (content.document.readyState != "uninitialized" && |
michael@0 | 65 | !webProgress.isLoadingDocument); |
michael@0 | 66 | |
michael@0 | 67 | sendAsyncMessage(cx.name, {isLoaded: isLoaded}); |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | // ---------- |
michael@0 | 71 | // Function: isImageDocument |
michael@0 | 72 | // Checks if the currently active document is an image document or not. |
michael@0 | 73 | isImageDocument: function WMH_isImageDocument(cx) { |
michael@0 | 74 | let isImageDocument = (content.document instanceof Ci.nsIImageDocument); |
michael@0 | 75 | |
michael@0 | 76 | sendAsyncMessage(cx.name, {isImageDocument: isImageDocument}); |
michael@0 | 77 | } |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | // add message listeners |
michael@0 | 81 | addMessageListener("Panorama:isDocumentLoaded", WindowMessageHandler.isDocumentLoaded); |
michael@0 | 82 | addMessageListener("Panorama:isImageDocument", WindowMessageHandler.isImageDocument); |
michael@0 | 83 |