|
|
@ -30,23 +30,11 @@ function log(aMsg) { |
|
|
|
Services.console.logStringMessage(msg); |
|
|
|
Services.console.logStringMessage(msg); |
|
|
|
dump(msg + '\n'); |
|
|
|
dump(msg + '\n'); |
|
|
|
} |
|
|
|
} |
|
|
|
function getWindow(top, id) { |
|
|
|
|
|
|
|
return top.QueryInterface(Ci.nsIInterfaceRequestor) |
|
|
|
function getDOMWindow(aChannel) { |
|
|
|
.getInterface(Ci.nsIDOMWindowUtils) |
|
|
|
var requestor = aChannel.notificationCallbacks; |
|
|
|
.getOuterWindowWithId(id); |
|
|
|
var win = requestor.getInterface(Components.interfaces.nsIDOMWindow); |
|
|
|
} |
|
|
|
return win; |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// All the priviledged actions.
|
|
|
|
// All the priviledged actions.
|
|
|
@ -75,6 +63,12 @@ ChromeActions.prototype = { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getDOMWindow(aChannel) { |
|
|
|
|
|
|
|
var requestor = aChannel.notificationCallbacks; |
|
|
|
|
|
|
|
var win = requestor.getInterface(Components.interfaces.nsIDOMWindow); |
|
|
|
|
|
|
|
return win; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Event listener to trigger chrome privedged code.
|
|
|
|
// Event listener to trigger chrome privedged code.
|
|
|
|
function RequestListener(actions) { |
|
|
|
function RequestListener(actions) { |
|
|
|
this.actions = actions; |
|
|
|
this.actions = actions; |
|
|
@ -163,38 +157,29 @@ PdfStreamConverter.prototype = { |
|
|
|
var channel = ioService.newChannel( |
|
|
|
var channel = ioService.newChannel( |
|
|
|
'resource://pdf.js/web/viewer.html', null, null); |
|
|
|
'resource://pdf.js/web/viewer.html', null, null); |
|
|
|
|
|
|
|
|
|
|
|
// Keep the URL the same so the browser sees it as the same.
|
|
|
|
var listener = this.listener; |
|
|
|
channel.originalURI = aRequest.URI; |
|
|
|
// Proxy all the requst observer calls, when it gets to onStopRequst
|
|
|
|
channel.asyncOpen(this.listener, aContext); |
|
|
|
// we can get the dom window.
|
|
|
|
|
|
|
|
var proxy = { |
|
|
|
// Setup a global listener waiting for the next DOM to be created and verfiy
|
|
|
|
onStartRequest: function() { |
|
|
|
// that its the one we want by its URL. When the correct DOM is found create
|
|
|
|
listener.onStartRequest.apply(listener, arguments); |
|
|
|
// an event listener on that window for the pdf.js events that require
|
|
|
|
}, |
|
|
|
// chrome priviledges. Code snippet from John Galt.
|
|
|
|
onDataAvailable: function() { |
|
|
|
let window = aRequest.loadGroup.groupObserver |
|
|
|
listener.onDataAvailable.apply(listener, arguments); |
|
|
|
.QueryInterface(Ci.nsIWebProgress) |
|
|
|
}, |
|
|
|
.DOMWindow; |
|
|
|
onStopRequest: function() { |
|
|
|
let top = topWindow(window); |
|
|
|
var domWindow = getDOMWindow(channel); |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let requestListener = new RequestListener(new ChromeActions); |
|
|
|
let requestListener = new RequestListener(new ChromeActions); |
|
|
|
win.addEventListener(PDFJS_EVENT_ID, function(event) { |
|
|
|
domWindow.addEventListener(PDFJS_EVENT_ID, function(event) { |
|
|
|
requestListener.receive(event); |
|
|
|
requestListener.receive(event); |
|
|
|
}, false, true); |
|
|
|
}, false, true); |
|
|
|
} else if (!getWindow(top, id)) { |
|
|
|
listener.onStopRequest.apply(listener, arguments); |
|
|
|
top.removeEventListener('DOMWindowCreated', onDOMWinCreated, true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, true); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Keep the URL the same so the browser sees it as the same.
|
|
|
|
|
|
|
|
channel.originalURI = aRequest.URI; |
|
|
|
|
|
|
|
channel.asyncOpen(proxy, aContext); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// nsIRequestObserver::onStopRequest
|
|
|
|
// nsIRequestObserver::onStopRequest
|
|
|
|