From 06b3bb8214ee364c351dbd3e4e668e2ccb8cbad0 Mon Sep 17 00:00:00 2001 From: Soumya Himanish Mohapatra Date: Sun, 14 Jan 2018 08:34:29 +0530 Subject: [PATCH] Download button is now hidden for PDFs which are opened from 'file://' --- web/app.js | 15 ++++++++++++--- web/ui_utils.js | 9 +++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index 06531c9320d88..9c561f22d375b 100644 --- a/web/app.js +++ b/web/app.js @@ -15,9 +15,10 @@ /* globals PDFBug, Stats */ import { - animationStarted, DEFAULT_SCALE_VALUE, getPDFFileNameFromURL, isValidRotation, - MAX_SCALE, MIN_SCALE, noContextMenuHandler, normalizeWheelEventDelta, - parseQueryString, PresentationModeState, ProgressBar, RendererType + animationStarted, DEFAULT_SCALE_VALUE, getPDFFileNameFromURL, isFileSchema, + isValidRotation, MAX_SCALE, MIN_SCALE, noContextMenuHandler, + normalizeWheelEventDelta, parseQueryString, PresentationModeState, + ProgressBar, RendererType } from './ui_utils'; import { build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException, @@ -675,6 +676,8 @@ let PDFViewerApplication = { this.store = null; this.isInitialViewSet = false; this.downloadComplete = false; + this.url = ''; + this.baseUrl = ''; this.pdfSidebar.reset(); this.pdfOutlineViewer.reset(); @@ -737,6 +740,12 @@ let PDFViewerApplication = { } } + if (this.url && isFileSchema(this.url)) { + let appConfig = this.appConfig; + appConfig.toolbar.download.setAttribute('hidden', 'true'); + appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true'); + } + let loadingTask = getDocument(parameters); this.pdfLoadingTask = loadingTask; diff --git a/web/ui_utils.js b/web/ui_utils.js index cd2e5c23d2560..05540f1af3777 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -381,6 +381,14 @@ function noContextMenuHandler(evt) { evt.preventDefault(); } +function isFileSchema(url) { + let i = 0, ii = url.length; + while (i < ii && url[i].trim() === '') { + i++; + } + return url.substr(i, 7).toLowerCase() === 'file://'; +} + function isDataSchema(url) { let i = 0, ii = url.length; while (i < ii && url[i].trim() === '') { @@ -665,6 +673,7 @@ export { SCROLLBAR_PADDING, VERTICAL_PADDING, isValidRotation, + isFileSchema, cloneObj, PresentationModeState, RendererType,