[Pkg-javascript-commits] [pdf.js] 100/210: Refactors GetAnnotationsRequest and GetPageRequest
David Prévot
taffit at moszumanska.debian.org
Thu Jun 5 14:21:06 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch upstream
in repository pdf.js.
commit cc9643cf32abb76e87cdb59a62e58543b460441e
Author: Yury Delendik <ydelendik at mozilla.com>
Date: Thu May 8 15:02:53 2014 -0500
Refactors GetAnnotationsRequest and GetPageRequest
---
src/core/worker.js | 25 +++++++-----------------
src/display/api.js | 57 +++++++++++++++++++++++-------------------------------
src/shared/util.js | 1 -
3 files changed, 31 insertions(+), 52 deletions(-)
diff --git a/src/core/worker.js b/src/core/worker.js
index d98aa3a..15207a7 100644
--- a/src/core/worker.js
+++ b/src/core/worker.js
@@ -258,23 +258,19 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}, onFailure);
});
- handler.on('GetPageRequest', function wphSetupGetPage(data) {
- var pageIndex = data.pageIndex;
- pdfManager.getPage(pageIndex).then(function(page) {
+ handler.on('GetPage', function wphSetupGetPage(data) {
+ return pdfManager.getPage(data.pageIndex).then(function(page) {
var rotatePromise = pdfManager.ensure(page, 'rotate');
var refPromise = pdfManager.ensure(page, 'ref');
var viewPromise = pdfManager.ensure(page, 'view');
- Promise.all([rotatePromise, refPromise, viewPromise]).then(
+ return Promise.all([rotatePromise, refPromise, viewPromise]).then(
function(results) {
- var page = {
- pageIndex: data.pageIndex,
+ return {
rotate: results[0],
ref: results[1],
view: results[2]
};
-
- handler.send('GetPage', { pageInfo: page });
});
});
});
@@ -327,16 +323,9 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
pdfManager.updatePassword(data);
});
- handler.on('GetAnnotationsRequest', function wphSetupGetAnnotations(data) {
- pdfManager.getPage(data.pageIndex).then(function(page) {
- pdfManager.ensure(page, 'getAnnotationsData', []).then(
- function(annotationsData) {
- handler.send('GetAnnotations', {
- pageIndex: data.pageIndex,
- annotations: annotationsData
- });
- }
- );
+ handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
+ return pdfManager.getPage(data.pageIndex).then(function(page) {
+ return pdfManager.ensure(page, 'getAnnotationsData', []);
});
});
diff --git a/src/display/api.js b/src/display/api.js
index 9d8de4d..f9ee1f5 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -387,7 +387,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* @class
*/
var PDFPageProxy = (function PDFPageProxyClosure() {
- function PDFPageProxy(pageInfo, transport) {
+ function PDFPageProxy(pageIndex, pageInfo, transport) {
+ this.pageIndex = pageIndex;
this.pageInfo = pageInfo;
this.transport = transport;
this.stats = new StatTimer();
@@ -403,7 +404,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @return {number} Page number of the page. First page is 1.
*/
get pageNumber() {
- return this.pageInfo.pageIndex + 1;
+ return this.pageIndex + 1;
},
/**
* @return {number} The number of degrees the page is rotated clockwise.
@@ -443,14 +444,13 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* annotation objects.
*/
getAnnotations: function PDFPageProxy_getAnnotations() {
- if (this.annotationsCapability) {
- return this.annotationsCapability.promise;
+ if (this.annotationsPromise) {
+ return this.annotationsPromise;
}
- var capability = createPromiseCapability();
- this.annotationsCapability = capability;
- this.transport.getAnnotations(this.pageInfo.pageIndex);
- return capability.promise;
+ var promise = this.transport.getAnnotations(this.pageIndex);
+ this.annotationsPromise = promise;
+ return promise;
},
/**
* Begins the process of rendering a page to the desired context.
@@ -576,6 +576,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
delete this.intentStates[intent];
}, this);
this.objs.clear();
+ this.annotationsPromise = null;
this.pendingDestroy = false;
},
/**
@@ -631,7 +632,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.commonObjs = new PDFObjects();
this.pageCache = [];
- this.pageCapabilities = [];
+ this.pagePromises = [];
this.downloadInfoCapability = createPromiseCapability();
this.passwordCallback = null;
@@ -699,7 +700,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
WorkerTransport.prototype = {
destroy: function WorkerTransport_destroy() {
this.pageCache = [];
- this.pageCapabilities = [];
+ this.pagePromises = [];
var self = this;
this.messageHandler.sendWithPromise('Terminate', null).then(function () {
FontLoader.clear();
@@ -821,20 +822,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.downloadInfoCapability.resolve(data);
}, this);
- messageHandler.on('GetPage', function transportPage(data) {
- var pageInfo = data.pageInfo;
- var page = new PDFPageProxy(pageInfo, this);
- this.pageCache[pageInfo.pageIndex] = page;
- var promise = this.pageCapabilities[pageInfo.pageIndex];
- promise.resolve(page);
- }, this);
-
- messageHandler.on('GetAnnotations', function transportAnnotations(data) {
- var annotations = data.annotations;
- var promise = this.pageCache[data.pageIndex].annotationsCapability;
- promise.resolve(annotations);
- }, this);
-
messageHandler.on('StartRenderPage', function transportRender(data) {
var page = this.pageCache[data.pageIndex];
@@ -943,7 +930,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
var components = data[1];
if (components != 3 && components != 1) {
return Promise.reject(
- new Error('Only 3 component or 1 component can be returned'));
+ new Error('Only 3 components or 1 component can be returned'));
}
return new Promise(function (resolve, reject) {
@@ -978,7 +965,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
};
img.src = imageUrl;
});
-
});
},
@@ -1010,13 +996,18 @@ var WorkerTransport = (function WorkerTransportClosure() {
}
var pageIndex = pageNumber - 1;
- if (pageIndex in this.pageCapabilities) {
- return this.pageCapabilities[pageIndex].promise;
+ if (pageIndex in this.pagePromises) {
+ return this.pagePromises[pageIndex];
}
- capability = createPromiseCapability();
- this.pageCapabilities[pageIndex] = capability;
- this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex });
- return capability.promise;
+ var promise = this.messageHandler.sendWithPromise('GetPage', {
+ pageIndex: pageIndex
+ }).then(function (pageInfo) {
+ var page = new PDFPageProxy(pageIndex, pageInfo, this);
+ this.pageCache[pageIndex] = page;
+ return page;
+ }.bind(this));
+ this.pagePromises[pageIndex] = promise;
+ return promise;
},
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
@@ -1024,7 +1015,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
},
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
- this.messageHandler.send('GetAnnotationsRequest',
+ return this.messageHandler.sendWithPromise('GetAnnotations',
{ pageIndex: pageIndex });
},
diff --git a/src/shared/util.js b/src/shared/util.js
index aabb000..75773fd 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -1448,7 +1448,6 @@ MessageHandler.prototype = {
* @param {String} actionName Action to call.
* @param {JSON} data JSON data to send.
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
- * @param {boolean} withPromise true if response if expected.
* @returns {Promise} Promise to be resolved with response data.
*/
sendWithPromise:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list