Skip to content

Commit

Permalink
Merge pull request #4 from jlegewie/current
Browse files Browse the repository at this point in the history
update to current pdf.js version
  • Loading branch information
jlegewie committed Nov 14, 2014
2 parents a79e789 + de98380 commit 7e28190
Show file tree
Hide file tree
Showing 115 changed files with 3,024 additions and 1,352 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Brendan Dahl <[email protected]>
Bill Walker <[email protected]>
Chris G Jones <[email protected]>
David Quintana <[email protected]>
Felix Kälberer <@fkaelberer>
Jakob Miland <[email protected]>
Jonas Jenwald <[email protected]>
Julian Viereck
Expand Down
48 changes: 48 additions & 0 deletions examples/components/simpleviewer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<!--
Copyright 2014 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.
-->
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
<title>PDF.js viewer using built components</title>

<style>
body {
background-color: #808080;
margin: 0;
padding: 0;
}
</style>

<link rel="stylesheet" href="../../build/components/pdf_viewer.css">

<!-- for legacy browsers -->
<script src="../../build/components/compatibility.js"></script>
<script src="../../build/pdf.js"></script>
<script src="../../build/components/pdf_viewer.js"></script>
</head>

<body tabindex="1">
<div id="viewerContainer">
<div id="viewer" class="pdfViewer"></div>
</div>

<script src="simpleviewer.js"></script>
</body>
</html>

50 changes: 50 additions & 0 deletions examples/components/simpleviewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright 2014 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.
*/

'use strict';

if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
alert('Please build the library and components using\n' +
' `node make generic components`');
}

// In cases when the pdf.worker.js is located at the different folder than the
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
// shall be specified.
//
// PDFJS.workerSrc = '../../build/pdf.worker.js';

// Some PDFs need external cmaps.
//
// PDFJS.cMapUrl = '../../external/bcmaps/';
// PDFJS.cMapPacked = true;

var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';

var container = document.getElementById('viewerContainer');
var pdfViewer = new PDFJS.PDFViewer({
container: container
});

container.addEventListener('pagesinit', function () {
// we can use pdfViewer now, e.g. let's change default scale.
pdfViewer.currentScaleValue = 'page-width';
});

// Loading document.
PDFJS.getDocument(DEFAULT_URL).then(function (pdfDocument) {
// Document loaded, specifying document for the viewer.
pdfViewer.setDocument(pdfDocument);
});
5 changes: 3 additions & 2 deletions examples/learning/helloworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ <h1>'Hello, world!' example</h1>
// PDFJS.disableWorker = true;

//
// If pdf.js must be execute via eval or pdf.worker.js is located at the
// different location that pdf.js, specify workerSrc.
// In cases when the pdf.worker.js is located at the different folder than the
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
// shall be specified.
//
// PDFJS.workerSrc = '../../build/pdf.worker.js';

Expand Down
5 changes: 3 additions & 2 deletions examples/learning/prevnext.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ <h1>'Previous/Next' example</h1>
// PDFJS.disableWorker = true;

//
// If pdf.js must be execute via eval or pdf.worker.js is located at the
// different location that pdf.js, specify workerSrc.
// In cases when the pdf.worker.js is located at the different folder than the
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
// shall be specified.
//
// PDFJS.workerSrc = '../../build/pdf.worker.js';

Expand Down
1 change: 1 addition & 0 deletions examples/node/domstubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var style = {

function xmlEncode(s){
var i = 0, ch;
s = String(s);
while (i < s.length && (ch = s[i]) !== '&' && ch !== '<' &&
ch !== '\"' && ch !== '\n' && ch !== '\r' && ch !== '\t') {
i++;
Expand Down
3 changes: 2 additions & 1 deletion examples/node/pdf2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ global.window = global;
global.navigator = { userAgent: 'node' };
global.PDFJS = {};

require('./domstubs.js');

PDFJS.workerSrc = true;
require('../../build/singlefile/build/pdf.combined.js');
require('./domstubs.js');

// Loading file from file system into typed array
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
Expand Down
47 changes: 36 additions & 11 deletions extensions/firefox/content/PdfJsTelemetry-addon.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,42 @@ Cu.import('resource://gre/modules/Services.jsm');
const ADDON_ID = "[email protected]";

var Telemetry = Services.telemetry;
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_USED", 1, 2, 3, Telemetry.HISTOGRAM_BOOLEAN);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_FALLBACK_SHOWN", 1, 2, 3, Telemetry.HISTOGRAM_BOOLEAN);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_DOCUMENT_VERSION", 1, 10, 11, Telemetry.HISTOGRAM_LINEAR);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_DOCUMENT_GENERATOR", 1, 25, 26, Telemetry.HISTOGRAM_LINEAR);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_DOCUMENT_SIZE_KB", 2, 64 * 1024, 20, Telemetry.HISTOGRAM_EXPONENTIAL);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_EMBED", 1, 2, 3, Telemetry.HISTOGRAM_BOOLEAN);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_FONT_TYPES", 1, 19, 20, Telemetry.HISTOGRAM_LINEAR);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_FORM", 1, 2, 3, Telemetry.HISTOGRAM_BOOLEAN);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_PRINT", 1, 2, 3, Telemetry.HISTOGRAM_BOOLEAN);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_STREAM_TYPES", 1, 19, 20, Telemetry.HISTOGRAM_LINEAR);
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_VIEWER_TIME_TO_VIEW_MS", 1, 10000, 50, Telemetry.HISTOGRAM_EXPONENTIAL);

var registerAddonHistogram = Telemetry.registerAddonHistogram;
try {
// Swapping arguments of the registerAddonHistogram for older Firefox versions.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1069953.
var ffVersion = parseInt(Services.appinfo.platformVersion);
var oldTelemetryAPI = ffVersion < 36;
if (ffVersion === 36) {
// Probing FF36 to check if it has new API.
try {
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_36",
Telemetry.HISTOGRAM_LINEAR, 1, 40, 41);
var histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_36");
histogram.add(36);
} catch (e) {
oldTelemetryAPI = true;
}
}
if (oldTelemetryAPI) {
registerAddonHistogram = function (p1, p2, p3, p4, p5, p6) {
return Telemetry.registerAddonHistogram(p1, p2, p4, p5, p6, p3);
};
}
} catch (ex) { }

registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_USED', Telemetry.HISTOGRAM_BOOLEAN, 1, 2, 3);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_FALLBACK_SHOWN', Telemetry.HISTOGRAM_BOOLEAN, 1, 2, 3);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_DOCUMENT_VERSION', Telemetry.HISTOGRAM_LINEAR, 1, 10, 11);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_DOCUMENT_GENERATOR', Telemetry.HISTOGRAM_LINEAR, 1, 25, 26);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_DOCUMENT_SIZE_KB', Telemetry.HISTOGRAM_EXPONENTIAL, 2, 64 * 1024, 20);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_EMBED', Telemetry.HISTOGRAM_BOOLEAN, 1, 2, 3);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_FONT_TYPES', Telemetry.HISTOGRAM_LINEAR, 1, 19, 20);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_FORM', Telemetry.HISTOGRAM_BOOLEAN, 1, 2, 3);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_PRINT', Telemetry.HISTOGRAM_BOOLEAN, 1, 2, 3);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_STREAM_TYPES', Telemetry.HISTOGRAM_LINEAR, 1, 19, 20);
registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_TIME_TO_VIEW_MS', Telemetry.HISTOGRAM_EXPONENTIAL, 1, 10000, 50);


this.PdfJsTelemetry = {
Expand Down
91 changes: 55 additions & 36 deletions extensions/firefox/content/PdfStreamConverter.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ function getFindBar(domWindow) {
var browser = getContainingBrowser(domWindow);
try {
var tabbrowser = browser.getTabBrowser();
var tab = tabbrowser._getTabForBrowser(browser);
var tab;
//#if MOZCENTRAL
tab = tabbrowser.getTabForBrowser(browser);
//#else
if (tabbrowser.getTabForBrowser) {
tab = tabbrowser.getTabForBrowser(browser);
} else {
// _getTabForBrowser is depreciated in Firefox 35, see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1039500.
tab = tabbrowser._getTabForBrowser(browser);
}
//#endif
return tabbrowser.getFindBar(tab);
} catch (e) {
// FF22 has no _getTabForBrowser, and FF24 has no getFindBar
Expand Down Expand Up @@ -177,46 +188,38 @@ function makeContentReadable(obj, window) {
// PDF data storage
function PdfDataListener(length) {
this.length = length; // less than 0, if length is unknown
this.data = new Uint8Array(length >= 0 ? length : 0x10000);
this.position = 0;
this.buffer = null;
this.loaded = 0;
}

PdfDataListener.prototype = {
append: function PdfDataListener_append(chunk) {
var willBeLoaded = this.loaded + chunk.length;
if (this.length >= 0 && this.length < willBeLoaded) {
this.length = -1; // reset the length, server is giving incorrect one
// In most of the cases we will pass data as we receive it, but at the
// beginning of the loading we may accumulate some data.
if (!this.buffer) {
this.buffer = new Uint8Array(chunk);
} else {
var buffer = this.buffer;
var newBuffer = new Uint8Array(buffer.length + chunk.length);
newBuffer.set(buffer);
newBuffer.set(chunk, buffer.length);
this.buffer = newBuffer;
}
if (this.length < 0 && this.data.length < willBeLoaded) {
// data length is unknown and new chunk will not fit in the existing
// buffer, resizing the buffer by doubling the its last length
var newLength = this.data.length;
for (; newLength < willBeLoaded; newLength *= 2) {}
var newData = new Uint8Array(newLength);
newData.set(this.data);
this.data = newData;
this.loaded += chunk.length;
if (this.length >= 0 && this.length < this.loaded) {
this.length = -1; // reset the length, server is giving incorrect one
}
this.data.set(chunk, this.loaded);
this.loaded = willBeLoaded;
this.onprogress(this.loaded, this.length >= 0 ? this.length : void(0));
},
readData: function PdfDataListener_readData() {
var data = this.data.subarray(this.position, this.loaded);
this.position = this.loaded;
return data;
},
getData: function PdfDataListener_getData() {
var data = this.data;
if (this.loaded != data.length)
data = data.subarray(0, this.loaded);
delete this.data; // releasing temporary storage
return data;
var result = this.buffer;
this.buffer = null;
return result;
},
finish: function PdfDataListener_finish() {
this.isDataReady = true;
if (this.oncompleteCallback) {
this.oncompleteCallback(this.getData());
this.oncompleteCallback(this.readData());
}
},
error: function PdfDataListener_error(errorCode) {
Expand All @@ -232,7 +235,7 @@ PdfDataListener.prototype = {
set oncomplete(value) {
this.oncompleteCallback = value;
if (this.isDataReady) {
value(this.getData());
value(this.readData());
}
if (this.errorCode) {
value(null, this.errorCode);
Expand All @@ -255,7 +258,14 @@ function ChromeActions(domWindow, contentDispositionFilename) {

ChromeActions.prototype = {
isInPrivateBrowsing: function() {
return PrivateBrowsingUtils.isWindowPrivate(this.domWindow);
//#if !MOZCENTRAL
if (!PrivateBrowsingUtils.isContentWindowPrivate) {
// pbu.isContentWindowPrivate was not supported prior Firefox 35.
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1069059)
return PrivateBrowsingUtils.isWindowPrivate(this.domWindow);
}
//#endif
return PrivateBrowsingUtils.isContentWindowPrivate(this.domWindow);
},
download: function(data, sendResponse) {
var self = this;
Expand Down Expand Up @@ -554,7 +564,9 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
this.headers[aHeader] = aValue;
}
};
originalRequest.visitRequestHeaders(httpHeaderVisitor);
if (originalRequest.visitRequestHeaders) {
originalRequest.visitRequestHeaders(httpHeaderVisitor);
}

var self = this;
var xhr_onreadystatechange = function xhr_onreadystatechange() {
Expand Down Expand Up @@ -598,7 +610,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
if (!this.streamingEnabled) {
this.originalRequest.cancel(Cr.NS_BINDING_ABORTED);
this.originalRequest = null;
data = this.dataListener.getData();
data = this.dataListener.readData();
this.dataListener = null;
} else {
data = this.dataListener.readData();
Expand Down Expand Up @@ -874,8 +886,8 @@ PdfStreamConverter.prototype = {
} catch (e) {}

var rangeRequest = false;
var hash = aRequest.URI.ref;
if (isHttpRequest && !getBoolPref(PREF_PREFIX + '.disableRange', false)) {
var streamRequest = false;
if (isHttpRequest) {
var contentEncoding = 'identity';
try {
contentEncoding = aRequest.getResponseHeader('Content-Encoding');
Expand All @@ -886,13 +898,20 @@ PdfStreamConverter.prototype = {
acceptRanges = aRequest.getResponseHeader('Accept-Ranges');
} catch (e) {}

var hash = aRequest.URI.ref;
var isPDFBugEnabled = getBoolPref(PREF_PREFIX + '.pdfBugEnabled', false);
rangeRequest = contentEncoding === 'identity' &&
acceptRanges === 'bytes' &&
aRequest.contentLength >= 0 &&
hash.toLowerCase().indexOf('disablerange=true') < 0;
!getBoolPref(PREF_PREFIX + '.disableRange', false) &&
(!isPDFBugEnabled ||
hash.toLowerCase().indexOf('disablerange=true') < 0);
streamRequest = contentEncoding === 'identity' &&
aRequest.contentLength >= 0 &&
!getBoolPref(PREF_PREFIX + '.disableStream', false) &&
(!isPDFBugEnabled ||
hash.toLowerCase().indexOf('disablestream=true') < 0);
}
var streamRequest = !getBoolPref(PREF_PREFIX + '.disableStream', false) &&
hash.toLowerCase().indexOf('disablestream=true') < 0;

aRequest.QueryInterface(Ci.nsIChannel);

Expand Down
13 changes: 12 additions & 1 deletion extensions/firefox/content/PdfjsChromeUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,18 @@ let PdfjsChromeUtils = {
*/
function PdfjsFindbarWrapper(aBrowser) {
let tabbrowser = aBrowser.getTabBrowser();
let tab = tabbrowser._getTabForBrowser(aBrowser);
let tab;
//#if MOZCENTRAL
tab = tabbrowser.getTabForBrowser(aBrowser);
//#else
if (tabbrowser.getTabForBrowser) {
tab = tabbrowser.getTabForBrowser(aBrowser);
} else {
// _getTabForBrowser is depreciated in Firefox 35, see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1039500.
tab = tabbrowser._getTabForBrowser(aBrowser);
}
//#endif
this._findbar = tabbrowser.getFindBar(tab);
};

Expand Down
Loading

0 comments on commit 7e28190

Please sign in to comment.