Bug 965861 - Update pdf.js to version 0.8.990. r=bdahl

This commit is contained in:
Ryan VanderMeulen 2014-01-31 12:52:51 -05:00
parent e6466f5e55
commit b4b53f4dd3
6 changed files with 1880 additions and 1448 deletions

View File

@ -1,4 +1,4 @@
This is the pdf.js project output, https://github.com/mozilla/pdf.js
Current extension version is: 0.8.934
Current extension version is: 0.8.990

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,8 @@ var NetworkManager = (function NetworkManagerClosure() {
function NetworkManager(url, args) {
this.url = url;
args = args || {};
this.httpHeaders = args.httpHeaders || {};
this.isHttp = /^https?:/i.test(url);
this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
this.withCredentials = args.withCredentials || false;
this.getXhr = args.getXhr ||
function NetworkManager_getXhr() {
@ -101,7 +102,7 @@ var NetworkManager = (function NetworkManagerClosure() {
}
xhr.setRequestHeader(property, value);
}
if ('begin' in args && 'end' in args) {
if (this.isHttp && 'begin' in args && 'end' in args) {
var rangeStr = args.begin + '-' + (args.end - 1);
xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
pendingRequest.expectedStatus = 206;
@ -156,7 +157,7 @@ var NetworkManager = (function NetworkManagerClosure() {
delete this.pendingRequests[xhrId];
// success status == 0 can be on ftp, file and other protocols
if (xhr.status === 0 && /^https?:/i.test(this.url)) {
if (xhr.status === 0 && this.isHttp) {
if (pendingRequest.onError) {
pendingRequest.onError(xhr.status);
}

View File

@ -35,6 +35,7 @@ input,
button,
select {
font: message-box;
outline: none;
}
.hidden {
@ -839,6 +840,7 @@ html[dir="rtl"] .secondaryToolbarButton.print::before {
.secondaryToolbarButton.bookmark {
-moz-box-sizing: border-box;
box-sizing: border-box;
outline: none;
padding-top: 4px;
text-decoration: none;
}
@ -1486,28 +1488,29 @@ html[dir='rtl'] #documentPropertiesContainer .row > * {
color: black;
}
.grab-to-pan-grab * {
.grab-to-pan-grab {
cursor: url("images/grab.cur"), move !important;
cursor: -moz-grab !important;
cursor: grab !important;
}
.grab-to-pan-grabbing,
.grab-to-pan-grabbing * {
.grab-to-pan-grab *:not(input):not(textarea):not(button):not(select):not(:link) {
cursor: inherit !important;
}
.grab-to-pan-grab:active,
.grab-to-pan-grabbing {
cursor: url("images/grabbing.cur"), move !important;
cursor: -moz-grabbing !important;
cursor: grabbing !important;
}
.grab-to-pan-grab input,
.grab-to-pan-grab textarea,
.grab-to-pan-grab button,
.grab-to-pan-grab button *,
.grab-to-pan-grab select,
.grab-to-pan-grab option {
cursor: auto !important;
}
.grab-to-pan-grab a[href],
.grab-to-pan-grab a[href] * {
cursor: pointer !important;
position: fixed;
background: transparent;
display: block;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
z-index: 50000; /* should be higher than anything else in PDF.js! */
}
@page {

View File

@ -17,7 +17,7 @@
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory,
Preferences, ViewHistory, PageView, ThumbnailView,
Preferences, ViewHistory, PageView, ThumbnailView, URL,
noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
PresentationMode, HandTool, Promise, DocumentProperties */
@ -771,8 +771,6 @@ var PDFFindController = {
resumePageIdx: null,
resumeCallback: null,
state: null,
dirtyMatch: false,
@ -785,7 +783,7 @@ var PDFFindController = {
initialize: function(options) {
if(typeof PDFFindBar === 'undefined' || PDFFindBar === null) {
throw 'PDFFindController cannot be initialized ' +
throw 'PDFFindController cannot be initialized ' +
'without a PDFFindController instance';
}
@ -845,10 +843,8 @@ var PDFFindController = {
this.pageMatches[pageIndex] = matches;
this.updatePage(pageIndex);
if (this.resumePageIdx === pageIndex) {
var callback = this.resumeCallback;
this.resumePageIdx = null;
this.resumeCallback = null;
callback();
this.nextPageMatch();
}
},
@ -937,7 +933,6 @@ var PDFFindController = {
this.offset.pageIdx = currentPageIndex;
this.offset.matchIdx = null;
this.hadMatch = false;
this.resumeCallback = null;
this.resumePageIdx = null;
this.pageMatches = [];
var self = this;
@ -964,7 +959,7 @@ var PDFFindController = {
}
// If we're waiting on a page, we return since we can't do anything else.
if (this.resumeCallback) {
if (this.resumePageIdx) {
return;
}
@ -990,48 +985,49 @@ var PDFFindController = {
this.nextPageMatch();
},
nextPageMatch: function() {
if (this.resumePageIdx !== null)
console.error('There can only be one pending page.');
var matchesReady = function(matches) {
var offset = this.offset;
var numMatches = matches.length;
var previous = this.state.findPrevious;
if (numMatches) {
// There were matches for the page, so initialize the matchIdx.
this.hadMatch = true;
offset.matchIdx = previous ? numMatches - 1 : 0;
this.updateMatch(true);
} else {
// No matches attempt to search the next page.
this.advanceOffsetPage(previous);
if (offset.wrapped) {
offset.matchIdx = null;
if (!this.hadMatch) {
// No point in wrapping there were no matches.
this.updateMatch(false);
return;
}
matchesReady: function(matches) {
var offset = this.offset;
var numMatches = matches.length;
var previous = this.state.findPrevious;
if (numMatches) {
// There were matches for the page, so initialize the matchIdx.
this.hadMatch = true;
offset.matchIdx = previous ? numMatches - 1 : 0;
this.updateMatch(true);
// matches were found
return true;
} else {
// No matches attempt to search the next page.
this.advanceOffsetPage(previous);
if (offset.wrapped) {
offset.matchIdx = null;
if (!this.hadMatch) {
// No point in wrapping there were no matches.
this.updateMatch(false);
// while matches were not found, searching for a page
// with matches should nevertheless halt.
return true;
}
// Search the next page.
this.nextPageMatch();
}
}.bind(this);
var pageIdx = this.offset.pageIdx;
var pageMatches = this.pageMatches;
if (!pageMatches[pageIdx]) {
// The matches aren't ready setup a callback so we can be notified,
// when they are ready.
this.resumeCallback = function() {
matchesReady(pageMatches[pageIdx]);
};
this.resumePageIdx = pageIdx;
return;
// matches were not found (and searching is not done)
return false;
}
// The matches are finished already.
matchesReady(pageMatches[pageIdx]);
},
nextPageMatch: function() {
if (this.resumePageIdx !== null) {
console.error('There can only be one pending page.');
}
do {
var pageIdx = this.offset.pageIdx;
var matches = this.pageMatches[pageIdx];
if (!matches) {
// The matches don't exist yet for processing by "matchesReady",
// so set a resume point for when they do exist.
this.resumePageIdx = pageIdx;
break;
}
} while (!this.matchesReady(matches));
},
advanceOffsetPage: function(previous) {
@ -1909,16 +1905,17 @@ var GrabToPan = (function GrabToPanClosure() {
this._onmousedown = this._onmousedown.bind(this);
this._onmousemove = this._onmousemove.bind(this);
this._endPan = this._endPan.bind(this);
// This overlay will be inserted in the document when the mouse moves during
// a grab operation, to ensure that the cursor has the desired appearance.
var overlay = this.overlay = document.createElement('div');
overlay.className = 'grab-to-pan-grabbing';
}
GrabToPan.prototype = {
/**
* Class name of element which can be grabbed
*/
CSS_CLASS_GRAB: 'grab-to-pan-grab',
/**
* Class name of element which is being dragged & panned
*/
CSS_CLASS_GRABBING: 'grab-to-pan-grabbing',
/**
* Bind a mousedown event to the element to enable grab-detection.
@ -2001,7 +1998,6 @@ var GrabToPan = (function GrabToPanClosure() {
this.element.addEventListener('scroll', this._endPan, true);
event.preventDefault();
event.stopPropagation();
this.element.classList.remove(this.CSS_CLASS_GRAB);
this.document.documentElement.classList.add(this.CSS_CLASS_GRABBING);
},
@ -2011,13 +2007,16 @@ var GrabToPan = (function GrabToPanClosure() {
_onmousemove: function GrabToPan__onmousemove(event) {
this.element.removeEventListener('scroll', this._endPan, true);
if (isLeftMouseReleased(event)) {
this.document.removeEventListener('mousemove', this._onmousemove, true);
this._endPan();
return;
}
var xDiff = event.clientX - this.clientXStart;
var yDiff = event.clientY - this.clientYStart;
this.element.scrollTop = this.scrollTopStart - yDiff;
this.element.scrollLeft = this.scrollLeftStart - xDiff;
if (!this.overlay.parentNode) {
document.body.appendChild(this.overlay);
}
},
/**
@ -2027,8 +2026,9 @@ var GrabToPan = (function GrabToPanClosure() {
this.element.removeEventListener('scroll', this._endPan, true);
this.document.removeEventListener('mousemove', this._onmousemove, true);
this.document.removeEventListener('mouseup', this._endPan, true);
this.document.documentElement.classList.remove(this.CSS_CLASS_GRABBING);
this.element.classList.add(this.CSS_CLASS_GRAB);
if (this.overlay.parentNode) {
this.overlay.parentNode.removeChild(this.overlay);
}
}
};
@ -2186,7 +2186,7 @@ var DocumentProperties = {
this.fileName = getPDFFileNameFromURL(PDFView.url);
// Get the file size.
PDFView.pdfDocument.dataLoaded().then(function(data) {
PDFView.pdfDocument.getDownloadInfo().then(function(data) {
self.setFileSize(data.length);
});
@ -2681,6 +2681,11 @@ var PDFView = {
};
window.addEventListener('message', function windowMessage(e) {
if (e.source !== null) {
// The message MUST originate from Chrome code.
console.warn('Rejected untrusted message from ' + e.origin);
return;
}
var args = e.data;
if (typeof args !== 'object' || !('pdfjsLoadAction' in args))
@ -2989,7 +2994,7 @@ var PDFView = {
var errorWrapper = document.getElementById('errorWrapper');
errorWrapper.setAttribute('hidden', 'true');
pdfDocument.dataLoaded().then(function() {
pdfDocument.getDownloadInfo().then(function() {
PDFView.loadingBar.hide();
var outerContainer = document.getElementById('outerContainer');
outerContainer.classList.remove('loadingInProgress');
@ -5181,30 +5186,6 @@ window.addEventListener('hashchange', function webViewerHashchange(evt) {
}
});
window.addEventListener('change', function webViewerChange(evt) {
var files = evt.target.files;
if (!files || files.length === 0)
return;
// Read the local file into a Uint8Array.
var fileReader = new FileReader();
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
var buffer = evt.target.result;
var uint8Array = new Uint8Array(buffer);
PDFView.open(uint8Array, 0);
};
var file = files[0];
fileReader.readAsArrayBuffer(file);
PDFView.setTitleUsingUrl(file.name);
// URL does not reflect proper document location - hiding some icons.
document.getElementById('viewBookmark').setAttribute('hidden', 'true');
document.getElementById('secondaryViewBookmark').
setAttribute('hidden', 'true');
document.getElementById('download').setAttribute('hidden', 'true');
document.getElementById('secondaryDownload').setAttribute('hidden', 'true');
}, true);
function selectScaleOption(value) {
var options = document.getElementById('scaleSelect').options;
@ -5294,19 +5275,22 @@ window.addEventListener('pagechange', function pagechange(evt) {
document.getElementById('next').disabled = (page >= PDFView.pages.length);
}, true);
// Firefox specific event, so that we can prevent browser from zooming
window.addEventListener('DOMMouseScroll', function(evt) {
if (evt.ctrlKey) {
evt.preventDefault();
function handleMouseWheel(evt) {
var MOUSE_WHEEL_DELTA_FACTOR = 40;
var ticks = (evt.type === 'DOMMouseScroll') ? -evt.detail :
evt.wheelDelta / MOUSE_WHEEL_DELTA_FACTOR;
var direction = (ticks < 0) ? 'zoomOut' : 'zoomIn';
var ticks = evt.detail;
var direction = (ticks > 0) ? 'zoomOut' : 'zoomIn';
if (evt.ctrlKey) { // Only zoom the pages, not the entire viewer
evt.preventDefault();
PDFView[direction](Math.abs(ticks));
} else if (PresentationMode.active) {
var FIREFOX_DELTA_FACTOR = -40;
PDFView.mouseScroll(evt.detail * FIREFOX_DELTA_FACTOR);
PDFView.mouseScroll(ticks * MOUSE_WHEEL_DELTA_FACTOR);
}
}, false);
}
window.addEventListener('DOMMouseScroll', handleMouseWheel);
window.addEventListener('mousewheel', handleMouseWheel);
window.addEventListener('click', function click(evt) {
if (!PresentationMode.active) {