Using blob URL for open file

This commit is contained in:
Yury Delendik 2014-01-27 13:11:02 -06:00
parent 141669a318
commit 18515b8668
2 changed files with 22 additions and 15 deletions

View File

@ -45,7 +45,8 @@ var NetworkManager = (function NetworkManagerClosure() {
function NetworkManager(url, args) {
this.url = url;
args = args || {};
this.httpHeaders = args.httpHeaders || {};
this.isHttp = /^https?:/i.test(url);
this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
this.withCredentials = args.withCredentials || false;
this.getXhr = args.getXhr ||
function NetworkManager_getXhr() {
@ -107,7 +108,7 @@ var NetworkManager = (function NetworkManagerClosure() {
}
xhr.setRequestHeader(property, value);
}
if ('begin' in args && 'end' in args) {
if (this.isHttp && 'begin' in args && 'end' in args) {
var rangeStr = args.begin + '-' + (args.end - 1);
xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
pendingRequest.expectedStatus = 206;
@ -162,7 +163,7 @@ var NetworkManager = (function NetworkManagerClosure() {
delete this.pendingRequests[xhrId];
// success status == 0 can be on ftp, file and other protocols
if (xhr.status === 0 && /^https?:/i.test(this.url)) {
if (xhr.status === 0 && this.isHttp) {
if (pendingRequest.onError) {
pendingRequest.onError(xhr.status);
}

View File

@ -17,7 +17,7 @@
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory,
Preferences, ViewHistory, PageView, ThumbnailView,
Preferences, ViewHistory, PageView, ThumbnailView, URL,
noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
PresentationMode, HandTool, Promise, DocumentProperties */
@ -1821,8 +1821,6 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
// var streamUrl = response.streamUrl;
// if (streamUrl) {
// console.log('Found data stream for ' + file);
// // The blob stream can be used only once, so disable range requests.
// PDFJS.disableRange = true;
// PDFView.open(streamUrl, 0);
// PDFView.setTitleUsingUrl(file);
// return;
@ -1936,11 +1934,18 @@ window.addEventListener('hashchange', function webViewerHashchange(evt) {
}
});
//#if !(FIREFOX || MOZCENTRAL || CHROME)
window.addEventListener('change', function webViewerChange(evt) {
var files = evt.target.files;
if (!files || files.length === 0)
return;
var file = files[0];
if (!PDFJS.disableCreateObjectURL &&
typeof URL !== 'undefined' && URL.createObjectURL) {
PDFView.open(URL.createObjectURL(file), 0);
} else {
// Read the local file into a Uint8Array.
var fileReader = new FileReader();
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
@ -1948,9 +1953,9 @@ window.addEventListener('change', function webViewerChange(evt) {
var uint8Array = new Uint8Array(buffer);
PDFView.open(uint8Array, 0);
};
var file = files[0];
fileReader.readAsArrayBuffer(file);
}
PDFView.setTitleUsingUrl(file.name);
// URL does not reflect proper document location - hiding some icons.
@ -1960,6 +1965,7 @@ window.addEventListener('change', function webViewerChange(evt) {
document.getElementById('download').setAttribute('hidden', 'true');
document.getElementById('secondaryDownload').setAttribute('hidden', 'true');
}, true);
//#endif
function selectScaleOption(value) {
var options = document.getElementById('scaleSelect').options;