Download button is now hidden for PDFs which are opened from 'file://'

This commit is contained in:
Soumya Himanish Mohapatra 2018-01-14 08:34:29 +05:30
parent ba0a3aebd0
commit 06b3bb8214
2 changed files with 21 additions and 3 deletions

View File

@ -15,9 +15,10 @@
/* globals PDFBug, Stats */ /* globals PDFBug, Stats */
import { import {
animationStarted, DEFAULT_SCALE_VALUE, getPDFFileNameFromURL, isValidRotation, animationStarted, DEFAULT_SCALE_VALUE, getPDFFileNameFromURL, isFileSchema,
MAX_SCALE, MIN_SCALE, noContextMenuHandler, normalizeWheelEventDelta, isValidRotation, MAX_SCALE, MIN_SCALE, noContextMenuHandler,
parseQueryString, PresentationModeState, ProgressBar, RendererType normalizeWheelEventDelta, parseQueryString, PresentationModeState,
ProgressBar, RendererType
} from './ui_utils'; } from './ui_utils';
import { import {
build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException, build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException,
@ -675,6 +676,8 @@ let PDFViewerApplication = {
this.store = null; this.store = null;
this.isInitialViewSet = false; this.isInitialViewSet = false;
this.downloadComplete = false; this.downloadComplete = false;
this.url = '';
this.baseUrl = '';
this.pdfSidebar.reset(); this.pdfSidebar.reset();
this.pdfOutlineViewer.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); let loadingTask = getDocument(parameters);
this.pdfLoadingTask = loadingTask; this.pdfLoadingTask = loadingTask;

View File

@ -381,6 +381,14 @@ function noContextMenuHandler(evt) {
evt.preventDefault(); 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) { function isDataSchema(url) {
let i = 0, ii = url.length; let i = 0, ii = url.length;
while (i < ii && url[i].trim() === '') { while (i < ii && url[i].trim() === '') {
@ -665,6 +673,7 @@ export {
SCROLLBAR_PADDING, SCROLLBAR_PADDING,
VERTICAL_PADDING, VERTICAL_PADDING,
isValidRotation, isValidRotation,
isFileSchema,
cloneObj, cloneObj,
PresentationModeState, PresentationModeState,
RendererType, RendererType,