mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Merge with upstream
This commit is contained in:
commit
132ee01bc0
7 changed files with 128 additions and 105 deletions
|
@ -1,31 +1,35 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'use strict';
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
const PDF_CONTENT_TYPE = "application/pdf";
|
||||
const PDF_CONTENT_TYPE = 'application/pdf';
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
|
||||
function log(aMsg) {
|
||||
let msg = "pdfContentHandler.js: " + (aMsg.join ? aMsg.join("") : aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService)
|
||||
let msg = 'pdfContentHandler.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
||||
Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
|
||||
.logStringMessage(msg);
|
||||
dump(msg + "\n");
|
||||
};
|
||||
dump(msg + '\n');
|
||||
}
|
||||
|
||||
function fireEventTo(aName, aData, aWindow) {
|
||||
let window = aWindow.wrappedJSObject;
|
||||
let evt = window.document.createEvent("CustomEvent");
|
||||
evt.initCustomEvent("pdf" + aName, false, false, aData);
|
||||
let evt = window.document.createEvent('CustomEvent');
|
||||
evt.initCustomEvent('pdf' + aName, false, false, aData);
|
||||
window.document.dispatchEvent(evt);
|
||||
};
|
||||
}
|
||||
|
||||
function loadDocument(aWindow, aDocumentUrl) {
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||
let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
|
||||
.createInstance(Ci.nsIXMLHttpRequest);
|
||||
|
||||
xhr.onprogress = function updateProgress(evt) {
|
||||
if (evt.lengthComputable)
|
||||
fireEventTo(evt.type, evt.loaded / evt.total, aWindow);
|
||||
|
@ -47,15 +51,15 @@ function loadDocument(aWindow, aDocumentUrl) {
|
|||
view2.set(view);
|
||||
|
||||
fireEventTo(evt.type, arrayBuffer, aWindow);
|
||||
} catch(e) {
|
||||
log("Error - " + e);
|
||||
} catch (e) {
|
||||
log('Error - ' + e);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open("GET", aDocumentUrl);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.open('GET', aDocumentUrl);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.send(null);
|
||||
};
|
||||
}
|
||||
|
||||
let WebProgressListener = {
|
||||
init: function(aWindow, aUrl) {
|
||||
|
@ -73,11 +77,12 @@ let WebProgressListener = {
|
|||
.getInterface(Ci.nsIWebProgress);
|
||||
try {
|
||||
webProgress.removeProgressListener(this);
|
||||
} catch(e) {}
|
||||
} catch (e) {}
|
||||
webProgress.addProgressListener(this, flags);
|
||||
},
|
||||
|
||||
onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
||||
onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags,
|
||||
aStatus) {
|
||||
const complete = Ci.nsIWebProgressListener.STATE_IS_WINDOW +
|
||||
Ci.nsIWebProgressListener.STATE_STOP;
|
||||
if ((aStateFlags & complete) == complete && this._locationHasChanged) {
|
||||
|
@ -86,14 +91,17 @@ let WebProgressListener = {
|
|||
}
|
||||
},
|
||||
|
||||
onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
|
||||
onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf,
|
||||
aMaxSelf, aCurTotal, aMaxTotal) {
|
||||
},
|
||||
|
||||
onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI) {
|
||||
onLocationChange: function onLocationChange(aWebProgress, aRequest,
|
||||
aLocationURI) {
|
||||
this._locationHasChanged = true;
|
||||
},
|
||||
|
||||
onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
|
||||
onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus,
|
||||
aMessage) {
|
||||
},
|
||||
|
||||
onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) {
|
||||
|
@ -136,16 +144,16 @@ pdfContentHandler.prototype = {
|
|||
WebProgressListener.init(window, uri.spec);
|
||||
|
||||
try {
|
||||
let url = Services.prefs.getCharPref("extensions.pdf.js.url");
|
||||
url = url.replace("%s", uri.spec);
|
||||
let url = Services.prefs.getCharPref('extensions.pdf.js.url');
|
||||
url = url.replace('%s', uri.spec);
|
||||
window.location = url;
|
||||
} catch(e) {
|
||||
log("Error retrieving the pdf.js base url - " + e);
|
||||
} catch (e) {
|
||||
log('Error retrieving the pdf.js base url - ' + e);
|
||||
}
|
||||
},
|
||||
|
||||
classID: Components.ID("{2278dfd0-b75c-11e0-8257-1ba3d93c9f1a}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentHandler]),
|
||||
classID: Components.ID('{2278dfd0-b75c-11e0-8257-1ba3d93c9f1a}'),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentHandler])
|
||||
};
|
||||
|
||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([pdfContentHandler]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue