Skip to content

Commit

Permalink
Adds deprecation warning for the API calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Oct 21, 2015
1 parent d38c005 commit 61e7bde
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Promise, PasswordResponses, PasswordException, InvalidPDFException,
MissingPDFException, UnknownErrorException, FontFaceObject,
loadJpegStream, createScratchCanvas, CanvasGraphics, stringToBytes,
UnexpectedResponseException */
UnexpectedResponseException, deprecated */

'use strict';

Expand Down Expand Up @@ -259,6 +259,10 @@ PDFJS.getDocument = function getDocument(src,
var task = new PDFDocumentLoadingTask();

// Support of the obsolete arguments (for compatibility with API v1.0)
if (arguments.length > 1) {
deprecated('getDocument is called with pdfDataRangeTransport, ' +
'passwordCallback or progressCallback argument');
}
if (pdfDataRangeTransport) {
if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
// Not a PDFDataRangeTransport instance, trying to add missing properties.
Expand Down Expand Up @@ -791,6 +795,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {

// Obsolete parameter support
if (params.continueCallback) {
deprecated('render is used with continueCallback parameter');
renderTask.onContinue = params.continueCallback;
}

Expand Down Expand Up @@ -900,10 +905,10 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
},

/**
* Cleans up resources allocated by the page.
* Deprecated, use cleanup() instead.
* Cleans up resources allocated by the page. (deprecated)
*/
destroy: function() {
deprecated('page destroy method, use cleanup() instead');
this.cleanup();
},

Expand Down
5 changes: 5 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ function warn(msg) {
}
}

// Deprecated API function -- treateat as warnings.
function deprecated(details) {
warn('Deprecated API usage: ' + details);
}

// Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception.
function error(msg) {
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ var PDFPageView = (function PDFPageViewClosure() {
canvasContext: ctx,
viewport: this.viewport,
// intent: 'default', // === 'display'
continueCallback: renderContinueCallback
};
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
renderTask.onContinue = renderContinueCallback;

this.renderTask.promise.then(
function pdfPageRenderCallback() {
Expand Down
4 changes: 2 additions & 2 deletions web/pdf_thumbnail_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {

var renderContext = {
canvasContext: ctx,
viewport: drawViewport,
continueCallback: renderContinueCallback
viewport: drawViewport
};
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
renderTask.onContinue = renderContinueCallback;

renderTask.promise.then(
function pdfPageRenderCallback() {
Expand Down
14 changes: 9 additions & 5 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ var PDFViewerApplication = {
this.setTitleUsingUrl(file.originalUrl);
parameters.url = file.url;
}
if (pdfDataRangeTransport) {
parameters.range = pdfDataRangeTransport;
}
if (args) {
for (var prop in args) {
parameters[prop] = args[prop];
Expand All @@ -535,18 +538,19 @@ var PDFViewerApplication = {
var self = this;
self.downloadComplete = false;

var passwordNeeded = function passwordNeeded(updatePassword, reason) {
var loadingTask = PDFJS.getDocument(parameters);

loadingTask.onPassword = function passwordNeeded(updatePassword, reason) {
PasswordPrompt.updatePassword = updatePassword;
PasswordPrompt.reason = reason;
PasswordPrompt.open();
};

function getDocumentProgress(progressData) {
loadingTask.onProgress = function getDocumentProgress(progressData) {
self.progress(progressData.loaded / progressData.total);
}
};

PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded,
getDocumentProgress).then(
loadingTask.promise.then(
function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
},
Expand Down

0 comments on commit 61e7bde

Please sign in to comment.