Better way to add custom event listener.
This commit is contained in:
parent
b6f05fb8c6
commit
7a17676b06
@ -19,6 +19,18 @@ function log(aMsg) {
|
|||||||
Services.console.logStringMessage(msg);
|
Services.console.logStringMessage(msg);
|
||||||
dump(msg + '\n');
|
dump(msg + '\n');
|
||||||
}
|
}
|
||||||
|
function getWindow(top, id) top.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils)
|
||||||
|
.getOuterWindowWithId(id);
|
||||||
|
function windowID(win) win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils)
|
||||||
|
.outerWindowID;
|
||||||
|
function topWindow(win) win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
||||||
|
.rootTreeItem
|
||||||
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindow);
|
||||||
let application = Cc['@mozilla.org/fuel/application;1']
|
let application = Cc['@mozilla.org/fuel/application;1']
|
||||||
.getService(Ci.fuelIApplication);
|
.getService(Ci.fuelIApplication);
|
||||||
let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
|
let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
|
||||||
@ -131,20 +143,30 @@ PdfStreamConverter.prototype = {
|
|||||||
// that its the one we want by its URL. When the correct DOM is found create
|
// that its the one we want by its URL. When the correct DOM is found create
|
||||||
// an event listener on that window for the pdf.js events that require
|
// an event listener on that window for the pdf.js events that require
|
||||||
// chrome priviledges.
|
// chrome priviledges.
|
||||||
var url = aRequest.URI.spec;
|
let window = aRequest.loadGroup.groupObserver
|
||||||
var gb = Services.wm.getMostRecentWindow('navigator:browser');
|
.QueryInterface(Ci.nsIWebProgress)
|
||||||
var domListener = function domListener(event) {
|
.DOMWindow;
|
||||||
var doc = event.originalTarget;
|
let top = topWindow(window);
|
||||||
var win = doc.defaultView;
|
let id = windowID(window);
|
||||||
if (doc.location.href === url) {
|
window = null;
|
||||||
gb.removeEventListener('DOMContentLoaded', domListener);
|
|
||||||
var requestListener = new RequestListener(new ChromeActions());
|
top.addEventListener('DOMWindowCreated', function onDOMWinCreated(event) {
|
||||||
win.addEventListener(PDFJS_EVENT_ID, function(event) {
|
let doc = event.originalTarget;
|
||||||
requestListener.receive(event);
|
let win = doc.defaultView;
|
||||||
}, false, true);
|
|
||||||
|
if (id == windowID(win)) {
|
||||||
|
top.removeEventListener('DOMWindowCreated', onDOMWinCreated, true);
|
||||||
|
if (!doc.documentURIObject.equals(aRequest.URI))
|
||||||
|
return;
|
||||||
|
|
||||||
|
let requestListener = new RequestListener(new ChromeActions);
|
||||||
|
win.addEventListener(PDFJS_EVENT_ID, function(event) {
|
||||||
|
requestListener.receive(event);
|
||||||
|
}, false, true);
|
||||||
|
} else if (!getWindow(top, id)) {
|
||||||
|
top.removeEventListener('DOMWindowCreated', onDOMWinCreated, true);
|
||||||
}
|
}
|
||||||
};
|
}, true);
|
||||||
gb.addEventListener('DOMContentLoaded', domListener, false);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// nsIRequestObserver::onStopRequest
|
// nsIRequestObserver::onStopRequest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user