Services.console.logStringMessage(msg);
dump(msg + '\n');
}
-function getWindow(top, id) {
- return top.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils)
- .getOuterWindowWithId(id);
-}
-function windowID(win) {
- return win.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils)
- .outerWindowID;
-}
-function topWindow(win) {
- return win.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsIDocShellTreeItem)
- .rootTreeItem
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow);
+
+function getDOMWindow(aChannel) {
+ var requestor = aChannel.notificationCallbacks;
+ var win = requestor.getInterface(Components.interfaces.nsIDOMWindow);
+ return win;
}
// All the priviledged actions.
}
};
+function getDOMWindow(aChannel) {
+ var requestor = aChannel.notificationCallbacks;
+ var win = requestor.getInterface(Components.interfaces.nsIDOMWindow);
+ return win;
+}
+
// Event listener to trigger chrome privedged code.
function RequestListener(actions) {
this.actions = actions;
var channel = ioService.newChannel(
'resource://pdf.js/web/viewer.html', null, null);
- // Keep the URL the same so the browser sees it as the same.
- channel.originalURI = aRequest.URI;
- channel.asyncOpen(this.listener, aContext);
-
- // Setup a global listener waiting for the next DOM to be created and verfiy
- // 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
- // chrome priviledges. Code snippet from John Galt.
- let window = aRequest.loadGroup.groupObserver
- .QueryInterface(Ci.nsIWebProgress)
- .DOMWindow;
- let top = topWindow(window);
- let id = windowID(window);
- window = null;
-
- top.addEventListener('DOMWindowCreated', function onDOMWinCreated(event) {
- let doc = event.originalTarget;
- let win = doc.defaultView;
-
- if (id == windowID(win)) {
- top.removeEventListener('DOMWindowCreated', onDOMWinCreated, true);
- if (!doc.documentURIObject.equals(aRequest.URI))
- return;
-
+ var listener = this.listener;
+ // Proxy all the requst observer calls, when it gets to onStopRequst
+ // we can get the dom window.
+ var proxy = {
+ onStartRequest: function() {
+ listener.onStartRequest.apply(listener, arguments);
+ },
+ onDataAvailable: function() {
+ listener.onDataAvailable.apply(listener, arguments);
+ },
+ onStopRequest: function() {
+ var domWindow = getDOMWindow(channel);
let requestListener = new RequestListener(new ChromeActions);
- win.addEventListener(PDFJS_EVENT_ID, function(event) {
+ domWindow.addEventListener(PDFJS_EVENT_ID, function(event) {
requestListener.receive(event);
}, false, true);
- } else if (!getWindow(top, id)) {
- top.removeEventListener('DOMWindowCreated', onDOMWinCreated, true);
+ listener.onStopRequest.apply(listener, arguments);
}
- }, true);
+ };
+
+ // Keep the URL the same so the browser sees it as the same.
+ channel.originalURI = aRequest.URI;
+ channel.asyncOpen(proxy, aContext);
},
// nsIRequestObserver::onStopRequest