2011-09-28 04:15:06 +09:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2011-09-07 07:00:24 +09:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2011-09-28 04:15:06 +09:00
|
|
|
const PDF_CONTENT_TYPE = 'application/pdf';
|
2011-09-07 07:00:24 +09:00
|
|
|
|
2011-09-28 04:15:06 +09:00
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
Cu.import('resource://gre/modules/Services.jsm');
|
2011-09-07 07:00:24 +09:00
|
|
|
|
|
|
|
function log(aMsg) {
|
2011-09-28 04:15:06 +09:00
|
|
|
let msg = 'pdfContentHandler.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
|
|
|
Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
|
2011-09-07 07:00:24 +09:00
|
|
|
.logStringMessage(msg);
|
2011-09-28 04:15:06 +09:00
|
|
|
dump(msg + '\n');
|
|
|
|
}
|
2011-09-07 07:00:24 +09:00
|
|
|
|
|
|
|
function pdfContentHandler() {
|
|
|
|
}
|
|
|
|
|
|
|
|
pdfContentHandler.prototype = {
|
|
|
|
handleContent: function handleContent(aMimetype, aContext, aRequest) {
|
|
|
|
if (aMimetype != PDF_CONTENT_TYPE)
|
|
|
|
throw Cr.NS_ERROR_WONT_HANDLE_CONTENT;
|
|
|
|
|
|
|
|
if (!(aRequest instanceof Ci.nsIChannel))
|
|
|
|
throw Cr.NS_ERROR_WONT_HANDLE_CONTENT;
|
|
|
|
|
|
|
|
let window = null;
|
2011-10-15 20:20:15 +09:00
|
|
|
let callbacks = aRequest.notificationCallbacks ||
|
2011-09-07 07:00:24 +09:00
|
|
|
aRequest.loadGroup.notificationCallbacks;
|
|
|
|
if (!callbacks)
|
|
|
|
return;
|
|
|
|
|
|
|
|
aRequest.cancel(Cr.NS_BINDING_ABORTED);
|
|
|
|
let uri = aRequest.URI;
|
|
|
|
|
|
|
|
try {
|
2011-09-28 04:15:06 +09:00
|
|
|
let url = Services.prefs.getCharPref('extensions.pdf.js.url');
|
|
|
|
url = url.replace('%s', uri.spec);
|
2011-10-18 08:28:57 +09:00
|
|
|
|
|
|
|
window = callbacks.getInterface(Ci.nsIDOMWindow);
|
2011-09-07 07:00:24 +09:00
|
|
|
window.location = url;
|
2011-09-28 04:15:06 +09:00
|
|
|
} catch (e) {
|
2011-09-28 20:21:07 +09:00
|
|
|
log('Error retrieving the pdf.js base url - ' + e);
|
2011-09-07 07:00:24 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-09-28 04:15:06 +09:00
|
|
|
classID: Components.ID('{2278dfd0-b75c-11e0-8257-1ba3d93c9f1a}'),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentHandler])
|
2011-09-07 07:00:24 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
var NSGetFactory = XPCOMUtils.generateNSGetFactory([pdfContentHandler]);
|
|
|
|
|