diff --git a/src/lib/constants.js b/src/lib/constants.js index f29849b44..7874af5e8 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -86,6 +86,10 @@ export const X_REP_HINT_IMAGE = '[jpg?dimensions=2048x2048,png?dimensions=2048x2 export const X_REP_HINT_VIDEO_DASH = '[dash,mp4][filmstrip]'; export const X_REP_HINT_VIDEO_MP4 = '[mp4]'; +// X-Box-Accept-Encoding Header for requesting non-gzipped representation +export const X_BOX_ACCEPT_ENCODING_HEADER = 'x-box-accept-encoding'; +export const X_BOX_ACCEPT_ENCODING_IDENTITY = 'identity'; + export const PDFJS_CSS_UNITS = 96.0 / 72.0; // Should match CSS_UNITS in pdf_viewer.js export const PDFJS_MAX_AUTO_SCALE = 1.25; // Should match MAX_AUTO_SCALE in pdf_viewer.js export const PDFJS_WIDTH_PADDING_PX = 40; // Should match SCROLLBAR_PADDING in pdf_viewer.js diff --git a/src/lib/file.js b/src/lib/file.js index 66cb99ead..0e8a0bdd3 100644 --- a/src/lib/file.js +++ b/src/lib/file.js @@ -298,9 +298,8 @@ export function canDownload(file, previewOptions) { // Can download watermarked representation if base check passes, user has preview permissions, Preview is configured // to force watermarked downloads, and the file is watermarked - const canDownloadWatermarked = passBaseDownloadCheck && - hasPreviewPermission && - shouldDownloadWM(file, previewOptions); + const canDownloadWatermarked = + passBaseDownloadCheck && hasPreviewPermission && shouldDownloadWM(file, previewOptions); return canDownloadOriginal || canDownloadWatermarked; } diff --git a/src/lib/viewers/box3d/Box3DRenderer.js b/src/lib/viewers/box3d/Box3DRenderer.js index 2fd37e9df..c94a102d0 100644 --- a/src/lib/viewers/box3d/Box3DRenderer.js +++ b/src/lib/viewers/box3d/Box3DRenderer.js @@ -527,9 +527,9 @@ class Box3DRenderer extends EventEmitter { if (!this.vrCommonLoadPromise) { if (commonEntities) { this.vrCommonLoadPromise = this.box3d.importEntitiesFromUrl( - `${this.staticBaseURI}third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/WebVR/${ - commonEntities - }/entities.json`, + `${ + this.staticBaseURI + }third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/WebVR/${commonEntities}/entities.json`, { isExternal: true } ); } else { @@ -539,9 +539,9 @@ class Box3DRenderer extends EventEmitter { if (!this.vrGamepadLoadPromises[controllerName]) { this.vrGamepadLoadPromises[controllerName] = this.vrCommonLoadPromise.then(() => { return this.box3d.importEntitiesFromUrl( - `${this.staticBaseURI}third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/WebVR/${ - controllerName - }/entities.json`, + `${ + this.staticBaseURI + }third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/WebVR/${controllerName}/entities.json`, { isExternal: true } ); }); diff --git a/src/lib/viewers/doc/DocBaseViewer.js b/src/lib/viewers/doc/DocBaseViewer.js index 6362eac6f..df84f9ec0 100644 --- a/src/lib/viewers/doc/DocBaseViewer.js +++ b/src/lib/viewers/doc/DocBaseViewer.js @@ -17,7 +17,9 @@ import { DOC_STATIC_ASSETS_VERSION, PERMISSION_DOWNLOAD, PRELOAD_REP_NAME, - STATUS_SUCCESS + STATUS_SUCCESS, + X_BOX_ACCEPT_ENCODING_HEADER, + X_BOX_ACCEPT_ENCODING_IDENTITY } from '../../constants'; import { checkPermission, getRepresentation } from '../../file'; import { get, createAssetUrlCreator, getMidpoint, getDistance, getClosestPageToPinch } from '../../util'; @@ -564,6 +566,12 @@ class DocBaseViewer extends BaseViewer { }; } + // If range requests are enabled, request the non-gzip compressed version of the representation + if (!PDFJS.disableRange) { + docInitParams.httpHeaders = docInitParams.httpHeaders || {}; + docInitParams.httpHeaders[X_BOX_ACCEPT_ENCODING_HEADER] = X_BOX_ACCEPT_ENCODING_IDENTITY; + } + // Start timing document load this.startLoadTimer(); diff --git a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js index 74ecea034..733e864ad 100644 --- a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js +++ b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js @@ -17,6 +17,8 @@ import { STATUS_ERROR, STATUS_PENDING, STATUS_SUCCESS, + X_BOX_ACCEPT_ENCODING_HEADER, + X_BOX_ACCEPT_ENCODING_IDENTITY } from '../../../constants'; import { ICON_PRINT_CHECKMARK } from '../../../icons/icons'; @@ -850,6 +852,30 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { }); }); + it('should set a x-box-accept-encoding header when range requests are enabled', () => { + docBase.options.location = { + locale: 'en-GB' + }; + const isDisbled = PDFJS.disableRange; + sandbox.stub(Browser, 'isIOS').returns(false); + sandbox.stub(PDFJS, 'getDocument').returns(Promise.resolve({})); + + PDFJS.disableRange = false; + + return docBase.initViewer('').then(() => { + expect(PDFJS.getDocument).to.be.calledWith({ + url: '', + rangeChunkSize: 524288, + httpHeaders: { + [X_BOX_ACCEPT_ENCODING_HEADER]: X_BOX_ACCEPT_ENCODING_IDENTITY + } + }); + + // Reset to original value + PDFJS.disableRange = isDisbled; + }); + }); + it('should resolve the loading task and set the document/viewer', () => { const doc = { url: 'url' diff --git a/src/lib/viewers/media/Settings.js b/src/lib/viewers/media/Settings.js index 149407a39..e2b2ce385 100644 --- a/src/lib/viewers/media/Settings.js +++ b/src/lib/viewers/media/Settings.js @@ -99,21 +99,15 @@ const SETTINGS_TEMPLATE = `
${ICON_ARROW_LEFT}
${__('media_quality')}
-
+
${ICON_CHECK_MARK}
480p
-
+
${ICON_CHECK_MARK}
1080p
-
+
${ICON_CHECK_MARK}
${__('media_quality_auto')}