Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-minor] Remove the postMessageTransfers parameter, and thus the ability to manually disable transferring of data, from the API #11123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,14 @@ var WorkerMessageHandler = {

// check if Uint8Array can be sent to worker
if (!(data instanceof Uint8Array)) {
handler.send('test', false);
handler.send('test', null);
return;
}
// making sure postMessage transfers are working
var supportTransfers = data[0] === 255;
const supportTransfers = data[0] === 255;
handler.postMessageTransfers = supportTransfers;
// check if the response property is supported by xhr
var xhr = new XMLHttpRequest();
var responseExists = 'response' in xhr;
// check if the property is actually implemented
try {
xhr.responseType; // eslint-disable-line no-unused-expressions
} catch (e) {
responseExists = false;
}
if (!responseExists) {
handler.send('test', false);
return;
}
handler.send('test', {
supportTypedArray: true,
supportTransfers,
});

handler.send('test', { supportTransfers, });
});

handler.on('configure', function wphConfigure(data) {
Expand Down
13 changes: 4 additions & 9 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
* 2^16 = 65536.
* @property {PDFWorker} worker - (optional) The worker that will be used for
* the loading and parsing of the PDF data.
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
* in postMessage for ArrayBuffers. The default value is `true`.
* @property {number} verbosity - (optional) Controls the logging level; the
* constants from {VerbosityLevel} should be used.
* @property {string} docBaseUrl - (optional) The base URL of the document,
Expand Down Expand Up @@ -319,7 +317,6 @@ function getDocument(src) {

if (!worker) {
const workerParams = {
postMessageTransfers: params.postMessageTransfers,
verbosity: params.verbosity,
port: GlobalWorkerOptions.workerPort,
};
Expand Down Expand Up @@ -1476,8 +1473,6 @@ class LoopbackPort {
* @typedef {Object} PDFWorkerParameters
* @property {string} name - (optional) The name of the worker.
* @property {Object} port - (optional) The `workerPort`.
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
* in postMessage for ArrayBuffers. The default value is `true`.
* @property {number} verbosity - (optional) Controls the logging level; the
* constants from {VerbosityLevel} should be used.
*/
Expand Down Expand Up @@ -1568,15 +1563,15 @@ const PDFWorker = (function PDFWorkerClosure() {
* @param {PDFWorkerParameters} params - The worker initialization parameters.
*/
class PDFWorker {
constructor({ name = null, port = null, postMessageTransfers = true,
constructor({ name = null, port = null,
verbosity = getVerbosityLevel(), } = {}) {
if (port && pdfWorkerPorts.has(port)) {
throw new Error('Cannot use more than one PDFWorker per port');
}

this.name = name;
this.destroyed = false;
this.postMessageTransfers = postMessageTransfers !== false;
this.postMessageTransfers = true;
this.verbosity = verbosity;

this._readyCapability = createPromiseCapability();
Expand Down Expand Up @@ -1665,7 +1660,7 @@ const PDFWorker = (function PDFWorkerClosure() {
terminateEarly();
return; // worker was destroyed
}
if (data && data.supportTypedArray) {
if (data) { // supportTypedArray
this._messageHandler = messageHandler;
this._port = worker;
this._webWorker = worker;
Expand Down Expand Up @@ -1705,7 +1700,7 @@ const PDFWorker = (function PDFWorkerClosure() {
try {
messageHandler.send('test', testObj, [testObj.buffer]);
} catch (ex) {
info('Cannot use postMessage transfers');
warn('Cannot use postMessage transfers.');
testObj[0] = 0;
messageHandler.send('test', testObj);
}
Expand Down
5 changes: 0 additions & 5 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ const defaultOptions = {
value: false,
kind: OptionKind.API,
},
postMessageTransfers: {
/** @type {boolean} */
value: true,
kind: OptionKind.API,
},
verbosity: {
/** @type {number} */
value: 1,
Expand Down