1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/content.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +let Cu = Components.utils; 1.11 +let Ci = Components.interfaces; 1.12 + 1.13 +Cu.import("resource:///modules/tabview/utils.jsm"); 1.14 + 1.15 +// Bug 671101 - directly using webProgress in this context 1.16 +// causes docShells to leak 1.17 +this.__defineGetter__("webProgress", function () { 1.18 + let ifaceReq = docShell.QueryInterface(Ci.nsIInterfaceRequestor); 1.19 + return ifaceReq.getInterface(Ci.nsIWebProgress); 1.20 +}); 1.21 + 1.22 +// ---------- 1.23 +// WindowEventHandler 1.24 +// 1.25 +// Handles events dispatched by the content window. 1.26 +let WindowEventHandler = { 1.27 + // ---------- 1.28 + // Function: onDOMWillOpenModalDialog 1.29 + // Sends a synchronous message when the "onDOMWillOpenModalDialog" event 1.30 + // is fired right before a modal dialog will be opened by the current page. 1.31 + onDOMWillOpenModalDialog: function WEH_onDOMWillOpenModalDialog(event) { 1.32 + // (event.isTrusted == true) when the event is generated by a user action 1.33 + // and does not originate from a script. 1.34 + if (!event.isTrusted) 1.35 + return; 1.36 + 1.37 + // we're intentionally sending a synchronous message to handle this event 1.38 + // as quick as possible, switch the selected tab and hide the tabview 1.39 + // before the modal dialog is shown 1.40 + sendSyncMessage("Panorama:DOMWillOpenModalDialog"); 1.41 + }, 1.42 + 1.43 + // ---------- 1.44 + // Function: onMozAfterPaint 1.45 + // Sends an asynchronous message when the "onMozAfterPaint" event 1.46 + // is fired. 1.47 + onMozAfterPaint: function WEH_onMozAfterPaint(event) { 1.48 + if (event.clientRects.length > 0) { 1.49 + sendAsyncMessage("Panorama:MozAfterPaint"); 1.50 + } 1.51 + } 1.52 +}; 1.53 + 1.54 +// add event listeners 1.55 +addEventListener("DOMWillOpenModalDialog", WindowEventHandler.onDOMWillOpenModalDialog, false); 1.56 +addEventListener("MozAfterPaint", WindowEventHandler.onMozAfterPaint, false); 1.57 + 1.58 +// ---------- 1.59 +// WindowMessageHandler 1.60 +// 1.61 +// Handles messages sent by the chrome process. 1.62 +let WindowMessageHandler = { 1.63 + // ---------- 1.64 + // Function: isDocumentLoaded 1.65 + // Checks if the currently active document is loaded. 1.66 + isDocumentLoaded: function WMH_isDocumentLoaded(cx) { 1.67 + let isLoaded = (content.document.readyState != "uninitialized" && 1.68 + !webProgress.isLoadingDocument); 1.69 + 1.70 + sendAsyncMessage(cx.name, {isLoaded: isLoaded}); 1.71 + }, 1.72 + 1.73 + // ---------- 1.74 + // Function: isImageDocument 1.75 + // Checks if the currently active document is an image document or not. 1.76 + isImageDocument: function WMH_isImageDocument(cx) { 1.77 + let isImageDocument = (content.document instanceof Ci.nsIImageDocument); 1.78 + 1.79 + sendAsyncMessage(cx.name, {isImageDocument: isImageDocument}); 1.80 + } 1.81 +}; 1.82 + 1.83 +// add message listeners 1.84 +addMessageListener("Panorama:isDocumentLoaded", WindowMessageHandler.isDocumentLoaded); 1.85 +addMessageListener("Panorama:isImageDocument", WindowMessageHandler.isImageDocument); 1.86 +