Skip to content

Commit

Permalink
Merge pull request #9345 from himanish-star/hide-download-button
Browse files Browse the repository at this point in the history
Download button is now hidden for PDFs which are loaded from 'file://'
  • Loading branch information
Snuffleupagus committed Jan 18, 2018
2 parents f774abc + 06b3bb8 commit 96c573a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 12 additions & 3 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions web/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() === '') {
Expand Down Expand Up @@ -665,6 +673,7 @@ export {
SCROLLBAR_PADDING,
VERTICAL_PADDING,
isValidRotation,
isFileSchema,
cloneObj,
PresentationModeState,
RendererType,
Expand Down

0 comments on commit 96c573a

Please sign in to comment.