diff --git a/extensions/firefox/components/pdfContentHandler.js b/extensions/firefox/components/pdfContentHandler.js index 9186bfd8a..7746e41b6 100644 --- a/extensions/firefox/components/pdfContentHandler.js +++ b/extensions/firefox/components/pdfContentHandler.js @@ -20,115 +20,17 @@ function log(aMsg) { 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); - window.document.dispatchEvent(evt); -} - -function loadDocument(aWindow, aDocumentUrl) { - 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); - }; - - xhr.onerror = function error(evt) { - fireEventTo(evt.type, false, aWindow); - }; - - xhr.onload = function load(evt) { - let data = (xhr.mozResponseArrayBuffer || xhr.mozResponse || - xhr.responseArrayBuffer || xhr.response); - try { - let view = new Uint8Array(data); - - let window = aWindow.wrappedJSObject; - let arrayBuffer = new window.ArrayBuffer(data.byteLength); - let view2 = new window.Uint8Array(arrayBuffer); - view2.set(view); - - fireEventTo(evt.type, arrayBuffer, aWindow); - } catch (e) { - log('Error - ' + e); - } - }; - - xhr.open('GET', aDocumentUrl); - xhr.responseType = 'arraybuffer'; - xhr.send(null); -} - -let WebProgressListener = { - init: function WebProgressListenerInit(aWindow, aUrl) { - this._locationHasChanged = false; - this._documentUrl = aUrl; - - let flags = Ci.nsIWebProgress.NOTIFY_LOCATION | - Ci.nsIWebProgress.NOTIFY_STATE_NETWORK | - Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT; - - let docShell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShell); - let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebProgress); - try { - webProgress.removeProgressListener(this); - } catch (e) {} - webProgress.addProgressListener(this, flags); - }, - - onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, - aStatus) { - const complete = Ci.nsIWebProgressListener.STATE_IS_WINDOW + - Ci.nsIWebProgressListener.STATE_STOP; - if ((aStateFlags & complete) == complete && this._locationHasChanged) { - aWebProgress.removeProgressListener(this); - loadDocument(aWebProgress.DOMWindow, this._documentUrl); - } - }, - - onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, - aMaxSelf, aCurTotal, aMaxTotal) { - }, - - onLocationChange: function onLocationChange(aWebProgress, aRequest, - aLocationURI) { - this._locationHasChanged = true; - }, - - onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, - aMessage) { - }, - - onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) { - }, - - QueryInterface: function QueryInterface(aIID) { - if (aIID.equals(Ci.nsIWebProgressListener) || - aIID.equals(Ci.nsISupportsWeakReference) || - aIID.equals(Ci.nsISupports)) { - return this; - } - - throw Components.results.NS_ERROR_NO_INTERFACE; - } -}; - - +const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001; function pdfContentHandler() { } pdfContentHandler.prototype = { handleContent: function handleContent(aMimetype, aContext, aRequest) { if (aMimetype != PDF_CONTENT_TYPE) - throw Cr.NS_ERROR_WONT_HANDLE_CONTENT; + throw NS_ERROR_WONT_HANDLE_CONTENT; if (!(aRequest instanceof Ci.nsIChannel)) - throw Cr.NS_ERROR_WONT_HANDLE_CONTENT; + throw NS_ERROR_WONT_HANDLE_CONTENT; let window = null; let callbacks = aRequest.notificationCallbacks || @@ -136,19 +38,22 @@ pdfContentHandler.prototype = { if (!callbacks) return; - aRequest.cancel(Cr.NS_BINDING_ABORTED); - let uri = aRequest.URI; - window = callbacks.getInterface(Ci.nsIDOMWindow); - WebProgressListener.init(window, uri.spec); + let url = null; try { - let url = Services.prefs.getCharPref('extensions.pdf.js.url'); - url = url.replace('%s', uri.spec); - window.location = url; + url = Services.prefs.getCharPref('extensions.pdf.js.url'); } catch (e) { log('Error retrieving the pdf.js base url - ' + e); + throw NS_ERROR_WONT_HANDLE_CONTENT; } + + let targetUrl = aRequest.URI.spec; + if (targetUrl.indexOf('?pdfjs.action=download') >= 0) + throw NS_ERROR_WONT_HANDLE_CONTENT; + + aRequest.cancel(Cr.NS_BINDING_ABORTED); + window.location = url.replace('%s', targetUrl); }, classID: Components.ID('{2278dfd0-b75c-11e0-8257-1ba3d93c9f1a}'), @@ -157,4 +62,3 @@ pdfContentHandler.prototype = { var NSGetFactory = XPCOMUtils.generateNSGetFactory([pdfContentHandler]); - diff --git a/fonts.js b/fonts.js index bcec5d2ac..2ba6e2f7a 100644 --- a/fonts.js +++ b/fonts.js @@ -1329,7 +1329,7 @@ var Font = (function Font() { // Character to glyphs mapping 'cmap': createCMapTable(charstrings.slice(), - ('glyphIds' in font) ? font.glyphIds: null), + ('glyphIds' in font) ? font.glyphIds : null), // Font header 'head': (function fontFieldsHead() { @@ -2613,14 +2613,13 @@ var Type2CFF = (function type2CFF() { var glyph = charsets[i]; var code = glyphMap[glyph] || 0; - var mapping = glyphs[code] || glyphs[glyph] || {}; + var mapping = glyphs[code] || glyphs[glyph] || { width: defaultWidth }; var unicode = mapping.unicode; if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255)) unicode += kCmapGlyphOffset; - var width = ('width' in mapping) && isNum(mapping.width) ? mapping.width - : defaultWidth; + var width = isNum(mapping.width) ? mapping.width : defaultWidth; properties.encoding[code] = { unicode: unicode, width: width diff --git a/pdf.js b/pdf.js index 30337b898..378c17580 100644 --- a/pdf.js +++ b/pdf.js @@ -3607,8 +3607,8 @@ var Page = (function pagePage() { gfx.execute(this.code, xref, resources); gfx.endDrawing(); }, - rotatePoint: function pageRotatePoint(x, y) { - var rotate = this.rotate; + rotatePoint: function pageRotatePoint(x, y, reverse) { + var rotate = reverse ? (360 - this.rotate) : this.rotate; switch (rotate) { case 180: return {x: this.width - x, y: y}; @@ -3616,6 +3616,7 @@ var Page = (function pagePage() { return {x: this.width - y, y: this.height - x}; case 270: return {x: y, y: x}; + case 360: case 0: default: return {x: x, y: this.height - y}; diff --git a/web/images/bookmark.svg b/web/images/bookmark.svg new file mode 100644 index 000000000..2c1fa130d --- /dev/null +++ b/web/images/bookmark.svg @@ -0,0 +1,661 @@ + + + + diff --git a/web/images/download.svg b/web/images/download.svg new file mode 100644 index 000000000..2922c4331 --- /dev/null +++ b/web/images/download.svg @@ -0,0 +1,619 @@ + + + diff --git a/web/viewer.css b/web/viewer.css index e72bdc286..040b87bdf 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -8,6 +8,10 @@ body { padding: 0px; } +[hidden] { + display: none; +} + /* === Toolbar === */ #controls { background-color: #eee; @@ -34,6 +38,10 @@ body { margin: 4px; } +#controls > a > img { + margin: 2px; +} + #controls > button { line-height: 32px; } diff --git a/web/viewer.html b/web/viewer.html index 5da063b91..f348b6c58 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -64,12 +64,21 @@ Print + +
+ + + + -- @@ -78,7 +87,7 @@ -