Bug 1198724 - Update pdf.js to version 1.1.403. r=yury

This commit is contained in:
Ryan VanderMeulen 2015-08-26 10:10:01 -04:00
Родитель 9b6811fa01
Коммит 7d4d53c159
7 изменённых файлов: 161 добавлений и 211 удалений

Просмотреть файл

@ -1,3 +1,3 @@
This is the pdf.js project output, https://github.com/mozilla/pdf.js
Current extension version is: 1.1.366
Current extension version is: 1.1.403

Просмотреть файл

@ -15,7 +15,7 @@
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, PdfjsChromeUtils, PdfRedirector,
/* globals Components, Services, XPCOMUtils, PdfjsChromeUtils,
PdfjsContentUtils, DEFAULT_PREFERENCES, PdfStreamConverter */
'use strict';

Просмотреть файл

@ -1,138 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, NetUtil, dump */
'use strict';
var EXPORTED_SYMBOLS = ['PdfRedirector'];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
const PDF_CONTENT_TYPE = 'application/pdf';
const FIREFOX_ID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}';
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.jsm');
Cu.import('resource://gre/modules/NetUtil.jsm');
function getDOMWindow(aChannel) {
var requestor = aChannel.notificationCallbacks ?
aChannel.notificationCallbacks :
aChannel.loadGroup.notificationCallbacks;
var win = requestor.getInterface(Components.interfaces.nsIDOMWindow);
return win;
}
function getObjectUrl(window) {
// PlayPreview overlay "belongs" to the embed/object tag and consists of DIV
// and IFRAME. Starting from IFRAME and looking for first object tag.
var element = window.frameElement, containerElement;
if (!element) {
return null; // iframe tag
}
var tagName = element.nodeName;
while (tagName !== 'EMBED' && tagName !== 'OBJECT') {
containerElement = element;
element = element.parentNode;
if (!element) {
return null; // object tag was not found
}
tagName = element.nodeName;
}
// Checking if overlay is a proper PlayPreview overlay.
if (element.displayedType !== element.TYPE_NULL ||
element.pluginFallbackType !== element.PLUGIN_PLAY_PREVIEW) {
return null; // invalid plugin element overlay state
}
for (var i = 0; i < element.children.length; i++) {
if (element.children[i] === containerElement) {
return null; // invalid plugin element overlay
}
}
return element.srcURI.spec;
}
function PdfRedirector() {
}
PdfRedirector.prototype = {
// properties required for XPCOM registration:
classID: Components.ID('{8cbfd8d0-2042-4976-b3ef-d9dee1efb975}'),
classDescription: 'pdf.js Redirector',
contractID:
'@mozilla.org/streamconv;1?from=application/x-moz-playpreview-pdfjs&to=*/*',
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIStreamConverter,
Ci.nsIStreamListener,
Ci.nsIRequestObserver
]),
// nsIStreamConverter::convert
convert: function(aFromStream, aFromType, aToType, aCtxt) {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
// nsIStreamConverter::asyncConvertData
asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
// Store the listener passed to us
this.listener = aListener;
},
// nsIStreamListener::onDataAvailable
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
// Do nothing since all the data loading is handled by the viewer.
},
// nsIRequestObserver::onStartRequest
onStartRequest: function(aRequest, aContext) {
// Setup the request so we can use it below.
aRequest.QueryInterface(Ci.nsIChannel);
// Cancel the request so the viewer can handle it.
aRequest.cancel(Cr.NS_BINDING_ABORTED);
var domWindow = getDOMWindow(aRequest);
var pdfUrl = getObjectUrl(domWindow);
if (!pdfUrl) {
Services.console.logStringMessage(
'PdfRedirector.js: PDF location is not specified for OBJECT/EMBED tag');
return;
}
// Create a new channel that is viewer loaded as a resource.
var ioService = Services.io;
var channel = ioService.newChannel(pdfUrl, null, null);
channel.loadGroup = aRequest.loadGroup;
channel.asyncOpen(this.listener, aContext);
},
// nsIRequestObserver::onStopRequest
onStopRequest: function(aRequest, aContext, aStatusCode) {
// Do nothing
}
};

Просмотреть файл

@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '1.1.366';
PDFJS.build = '9e9df56';
PDFJS.version = '1.1.403';
PDFJS.build = '88e0326';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -1196,6 +1196,10 @@ function MessageHandler(name, comObj) {
data: result
});
}, function (reason) {
if (reason instanceof Error) {
// Serialize error to avoid "DataCloneError"
reason = reason + '';
}
comObj.postMessage({
isReply: true,
callbackId: data.callbackId,
@ -1439,6 +1443,14 @@ PDFJS.openExternalLinksInNewWindow = (
PDFJS.openExternalLinksInNewWindow === undefined ?
false : PDFJS.openExternalLinksInNewWindow);
/**
* Determines if we can eval strings as JS. Primarily used to improve
* performance for font rendering.
* @var {boolean}
*/
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
true : PDFJS.isEvalSupported);
/**
* Document initialization / loading parameters object.
*
@ -1549,6 +1561,8 @@ PDFJS.getDocument = function getDocument(src,
} else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
!isNaN(pdfBytes.length)) {
params[key] = new Uint8Array(pdfBytes);
} else if (isArrayBuffer(pdfBytes)) {
params[key] = new Uint8Array(pdfBytes);
} else {
error('Invalid PDF binary data: either typed array, string or ' +
'array-like object is expected in the data property.');
@ -5461,7 +5475,7 @@ var WebGLUtils = (function WebGLUtilsClosure() {
for (var j = 0, jj = ps.length; j < jj; j++) {
coords[pIndex] = coordsMap[ps[j]];
coords[pIndex + 1] = coordsMap[ps[j] + 1];
colors[cIndex] = colorsMap[cs[i]];
colors[cIndex] = colorsMap[cs[j]];
colors[cIndex + 1] = colorsMap[cs[j] + 1];
colors[cIndex + 2] = colorsMap[cs[j] + 2];
pIndex += 2;
@ -6026,9 +6040,40 @@ var FontFaceObject = (function FontFaceObjectClosure() {
getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
if (!(character in this.compiledGlyphs)) {
var js = objs.get(this.loadedName + '_path_' + character);
/*jshint -W054 */
this.compiledGlyphs[character] = new Function('c', 'size', js);
var cmds = objs.get(this.loadedName + '_path_' + character);
var current, i, len;
// If we can, compile cmds into JS for MAXIMUM SPEED
if (FontLoader.isEvalSupported) {
var args, js = '';
for (i = 0, len = cmds.length; i < len; i++) {
current = cmds[i];
if (current.args !== undefined) {
args = current.args.join(',');
} else {
args = '';
}
js += 'c.' + current.cmd + '(' + args + ');\n';
}
/* jshint -W054 */
this.compiledGlyphs[character] = new Function('c', 'size', js);
} else {
// But fall back on using Function.prototype.apply() if we're
// blocked from using eval() for whatever reason (like CSP policies)
this.compiledGlyphs[character] = function(c, size) {
for (i = 0, len = cmds.length; i < len; i++) {
current = cmds[i];
if (current.cmd === 'scale') {
current.args = [size, -size];
}
c[current.cmd].apply(c, current.args);
}
};
}
}
return this.compiledGlyphs[character];
}

Просмотреть файл

@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '1.1.366';
PDFJS.build = '9e9df56';
PDFJS.version = '1.1.403';
PDFJS.build = '88e0326';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -1196,6 +1196,10 @@ function MessageHandler(name, comObj) {
data: result
});
}, function (reason) {
if (reason instanceof Error) {
// Serialize error to avoid "DataCloneError"
reason = reason + '';
}
comObj.postMessage({
isReply: true,
callbackId: data.callbackId,
@ -3529,9 +3533,12 @@ var XRef = (function XRefClosure() {
indexObjects: function XRef_indexObjects() {
// Simple scan through the PDF content to find objects,
// trailers and XRef streams.
var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
var PERCENT = 0x25, LT = 0x3C;
function readToken(data, offset) {
var token = '', ch = data[offset];
while (ch !== 13 && ch !== 10) {
while (ch !== LF && ch !== CR && ch !== LT) {
if (++offset >= data.length) {
break;
}
@ -3563,6 +3570,9 @@ var XRef = (function XRefClosure() {
var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
// Clear out any existing entries, since they may be bogus.
this.entries.length = 0;
var stream = this.stream;
stream.pos = 0;
var buffer = stream.getBytes();
@ -3570,23 +3580,24 @@ var XRef = (function XRefClosure() {
var trailers = [], xrefStms = [];
while (position < length) {
var ch = buffer[position];
if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
++position;
continue;
}
if (ch === 37) { // %-comment
if (ch === PERCENT) { // %-comment
do {
++position;
if (position >= length) {
break;
}
ch = buffer[position];
} while (ch !== 13 && ch !== 10);
} while (ch !== LF && ch !== CR);
continue;
}
var token = readToken(buffer, position);
var m;
if (token === 'xref') {
if (token.indexOf('xref') === 0 &&
(token.length === 4 || /\s/.test(token[4]))) {
position += skipUntil(buffer, position, trailerBytes);
trailers.push(position);
position += skipUntil(buffer, position, startxrefBytes);
@ -11530,11 +11541,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xFFFF);
}
cmap = cmap.getMap();
var map = [];
// Convert UTF-16BE
// NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
// to iterate over all keys.
cmap.forEach(function(token, i) {
cmap.forEach(function(charCode, token) {
var str = [];
for (var k = 0; k < token.length; k += 2) {
var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
@ -11546,9 +11557,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
}
cmap[i] = String.fromCharCode.apply(String, str);
map[charCode] = String.fromCharCode.apply(String, str);
});
return new ToUnicodeMap(cmap);
return new ToUnicodeMap(map);
}
return null;
},
@ -18039,9 +18050,10 @@ var Font = (function FontClosure() {
if (!glyphName) {
continue;
}
var unicodeOrCharCode;
var unicodeOrCharCode, isUnicode = false;
if (cmapPlatformId === 3 && cmapEncodingId === 1) {
unicodeOrCharCode = GlyphsUnicode[glyphName];
isUnicode = true;
} else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
// TODO: the encoding needs to be updated with mac os table.
unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
@ -18049,8 +18061,11 @@ var Font = (function FontClosure() {
var found = false;
for (i = 0; i < cmapMappingsLength; ++i) {
if (cmapMappings[i].charCode === unicodeOrCharCode &&
hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode, -1)) {
if (cmapMappings[i].charCode !== unicodeOrCharCode) {
continue;
}
var code = isUnicode ? charCode : unicodeOrCharCode;
if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
found = true;
break;
@ -21258,16 +21273,15 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
return 0;
}
function compileGlyf(code, js, font) {
function compileGlyf(code, cmds, font) {
function moveTo(x, y) {
js.push('c.moveTo(' + x + ',' + y + ');');
cmds.push({cmd: 'moveTo', args: [x, y]});
}
function lineTo(x, y) {
js.push('c.lineTo(' + x + ',' + y + ');');
cmds.push({cmd: 'lineTo', args: [x, y]});
}
function quadraticCurveTo(xa, ya, x, y) {
js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
x + ',' + y + ');');
cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
}
var i = 0;
@ -21313,11 +21327,11 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
var subglyph = font.glyphs[glyphIndex];
if (subglyph) {
js.push('c.save();');
js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
compileGlyf(subglyph, js, font);
js.push('c.restore();');
cmds.push({cmd: 'save'});
cmds.push({cmd: 'transform',
args: [scaleX, scale01, scale10, scaleY, x, y]});
compileGlyf(subglyph, cmds, font);
cmds.push({cmd: 'restore'});
}
} while ((flags & 0x20));
} else {
@ -21413,20 +21427,19 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
}
function compileCharString(code, js, font) {
function compileCharString(code, cmds, font) {
var stack = [];
var x = 0, y = 0;
var stems = 0;
function moveTo(x, y) {
js.push('c.moveTo(' + x + ',' + y + ');');
cmds.push({cmd: 'moveTo', args: [x, y]});
}
function lineTo(x, y) {
js.push('c.lineTo(' + x + ',' + y + ');');
cmds.push({cmd: 'lineTo', args: [x, y]});
}
function bezierCurveTo(x1, y1, x2, y2, x, y) {
js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
x + ',' + y + ');');
cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
}
function parse(code) {
@ -21555,16 +21568,16 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
var bchar = stack.pop();
y = stack.pop();
x = stack.pop();
js.push('c.save();');
js.push('c.translate('+ x + ',' + y + ');');
cmds.push({cmd: 'save'});
cmds.push({cmd: 'translate', args: [x, y]});
var gid = lookupCmap(font.cmap, String.fromCharCode(
font.glyphNameMap[Encodings.StandardEncoding[achar]]));
compileCharString(font.glyphs[gid], js, font);
js.push('c.restore();');
compileCharString(font.glyphs[gid], cmds, font);
cmds.push({cmd: 'restore'});
gid = lookupCmap(font.cmap, String.fromCharCode(
font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
compileCharString(font.glyphs[gid], js, font);
compileCharString(font.glyphs[gid], cmds, font);
}
return;
case 18: // hstemhm
@ -21733,16 +21746,16 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
return noop;
}
var js = [];
js.push('c.save();');
js.push('c.transform(' + this.fontMatrix.join(',') + ');');
js.push('c.scale(size, -size);');
var cmds = [];
cmds.push({cmd: 'save'});
cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
cmds.push({cmd: 'scale', args: ['size', '-size']});
this.compileGlyphImpl(code, js);
this.compileGlyphImpl(code, cmds);
js.push('c.restore();');
cmds.push({cmd: 'restore'});
return js.join('\n');
return cmds;
},
compileGlyphImpl: function () {
@ -21766,8 +21779,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
Util.inherit(TrueTypeCompiled, CompiledFont, {
compileGlyphImpl: function (code, js) {
compileGlyf(code, js, this);
compileGlyphImpl: function (code, cmds) {
compileGlyf(code, cmds, this);
}
});
@ -21788,8 +21801,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
Util.inherit(Type2Compiled, CompiledFont, {
compileGlyphImpl: function (code, js) {
compileCharString(code, js, this);
compileGlyphImpl: function (code, cmds) {
compileCharString(code, cmds, this);
}
});
@ -26793,7 +26806,10 @@ var PDFImage = (function PDFImageClosure() {
}
return imgData;
}
if (this.image instanceof JpegStream && !this.smask && !this.mask) {
if (this.image instanceof JpegStream && !this.smask && !this.mask &&
(this.colorSpace.name === 'DeviceGray' ||
this.colorSpace.name === 'DeviceRGB' ||
this.colorSpace.name === 'DeviceCMYK')) {
imgData.kind = ImageKind.RGB_24BPP;
imgData.data = this.getImageBytes(originalHeight * rowBytes,
drawWidth, drawHeight, true);
@ -30344,7 +30360,7 @@ var Parser = (function ParserClosure() {
return stream;
},
makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
if (stream.dict.get('Length') === 0) {
if (stream.dict.get('Length') === 0 && !maybeLength) {
return new NullStream(stream);
}
try {

Просмотреть файл

@ -1415,6 +1415,10 @@ html[dir='rtl'] .attachmentsItem > button {
vertical-align: middle;
}
.dialog :link {
color: white;
}
#passwordOverlay > .dialog {
text-align: center;
}

Просмотреть файл

@ -1552,13 +1552,11 @@ var PDFLinkService = (function () {
this.page = pageNumber; // simple page
}
if ('pagemode' in params) {
if (params.pagemode === 'thumbs' || params.pagemode === 'bookmarks' ||
params.pagemode === 'attachments') {
this.switchSidebarView((params.pagemode === 'bookmarks' ?
'outline' : params.pagemode), true);
} else if (params.pagemode === 'none' && this.sidebarOpen) {
document.getElementById('sidebarToggle').click();
}
var event = document.createEvent('CustomEvent');
event.initCustomEvent('pagemode', true, true, {
mode: params.pagemode,
});
this.pdfViewer.container.dispatchEvent(event);
}
} else if (/^\d+$/.test(hash)) { // page number
this.page = hash;
@ -6790,29 +6788,27 @@ var PDFViewerApplication = {
break;
case 'outline':
if (outlineButton.disabled) {
return;
}
thumbsButton.classList.remove('toggled');
outlineButton.classList.add('toggled');
attachmentsButton.classList.remove('toggled');
thumbsView.classList.add('hidden');
outlineView.classList.remove('hidden');
attachmentsView.classList.add('hidden');
if (outlineButton.getAttribute('disabled')) {
return;
}
break;
case 'attachments':
if (attachmentsButton.disabled) {
return;
}
thumbsButton.classList.remove('toggled');
outlineButton.classList.remove('toggled');
attachmentsButton.classList.add('toggled');
thumbsView.classList.add('hidden');
outlineView.classList.add('hidden');
attachmentsView.classList.remove('hidden');
if (attachmentsButton.getAttribute('disabled')) {
return;
}
break;
}
},
@ -7195,18 +7191,45 @@ document.addEventListener('textlayerrendered', function (e) {
}
}, true);
document.addEventListener('pagemode', function (evt) {
if (!PDFViewerApplication.initialized) {
return;
}
// Handle the 'pagemode' hash parameter, see also `PDFLinkService_setHash`.
var mode = evt.detail.mode;
switch (mode) {
case 'bookmarks':
// Note: Our code calls this property 'outline', even though the
// Open Parameter specification calls it 'bookmarks'.
mode = 'outline';
/* falls through */
case 'thumbs':
case 'attachments':
PDFViewerApplication.switchSidebarView(mode, true);
break;
case 'none':
if (PDFViewerApplication.sidebarOpen) {
document.getElementById('sidebarToggle').click();
}
break;
}
}, true);
document.addEventListener('namedaction', function (e) {
if (!PDFViewerApplication.initialized) {
return;
}
// Processing couple of named actions that might be useful.
// See also PDFLinkService.executeNamedAction
var action = e.action;
var action = e.detail.action;
switch (action) {
case 'GoToPage':
document.getElementById('pageNumber').focus();
break;
case 'Find':
if (!this.supportsIntegratedFind) {
this.findBar.toggle();
if (!PDFViewerApplication.supportsIntegratedFind) {
PDFViewerApplication.findBar.toggle();
}
break;
}