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