mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 15:48:06 +02:00
Remove streamsPrivate usage
This was only ever useful for the Opera extension because the API requires a whitelisted extension ID. Opera ditched PDF.js from their extension gallery, so we don't need to keep this in the tree.
This commit is contained in:
parent
11914277d5
commit
fc658a718c
4 changed files with 50 additions and 364 deletions
122
web/chromecom.js
122
web/chromecom.js
|
@ -75,83 +75,59 @@
|
|||
file = file.replace(/^drive:/i,
|
||||
'filesystem:' + location.origin + '/external/');
|
||||
|
||||
ChromeCom.request('getPDFStream', file, function(response) {
|
||||
if (response) {
|
||||
// We will only get a response when the streamsPrivate API is available.
|
||||
|
||||
var isFTPFile = /^ftp:/i.test(file);
|
||||
var streamUrl = response.streamUrl;
|
||||
if (streamUrl) {
|
||||
console.log('Found data stream for ' + file);
|
||||
callback(streamUrl, response.contentLength, file);
|
||||
if (/^filesystem:/.test(file) && !pdfjsLib.PDFJS.disableWorker) {
|
||||
// The security origin of filesystem:-URLs are not preserved when the
|
||||
// URL is passed to a Web worker, (http://crbug.com/362061), so we have
|
||||
// to create an intermediate blob:-URL as a work-around.
|
||||
var resolveLocalFileSystemURL = window.resolveLocalFileSystemURL ||
|
||||
window.webkitResolveLocalFileSystemURL;
|
||||
resolveLocalFileSystemURL(file, function onResolvedFSURL(fileEntry) {
|
||||
fileEntry.file(function(fileObject) {
|
||||
var blobUrl = URL.createObjectURL(fileObject);
|
||||
callback(blobUrl, fileObject.size);
|
||||
});
|
||||
}, function onFileSystemError(error) {
|
||||
// This should not happen. When it happens, just fall back to the
|
||||
// usual way of getting the File's data (via the Web worker).
|
||||
console.warn('Cannot resolve file ' + file + ', ' + error.name + ' ' +
|
||||
error.message);
|
||||
callback(file);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (/^https?:/.test(file)) {
|
||||
// Assumption: The file being opened is the file that was requested.
|
||||
// There is no UI to input a different URL, so this assumption will hold
|
||||
// for now.
|
||||
setReferer(file, function() {
|
||||
callback(file);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (/^file?:/.test(file)) {
|
||||
getEmbedderOrigin(function(origin) {
|
||||
// If the origin cannot be determined, let Chrome decide whether to
|
||||
// allow embedding files. Otherwise, only allow local files to be
|
||||
// embedded from local files or Chrome extensions.
|
||||
// Even without this check, the file load in frames is still blocked,
|
||||
// but this may change in the future (https://crbug.com/550151).
|
||||
if (origin && !/^file:|^chrome-extension:/.test(origin)) {
|
||||
PDFViewerApplication.error('Blocked ' + origin + ' from loading ' +
|
||||
file + '. Refused to load a local file in a non-local page ' +
|
||||
'for security reasons.');
|
||||
return;
|
||||
}
|
||||
if (isFTPFile && !response.extensionSupportsFTP) {
|
||||
// Stream not found, and it's loaded from FTP.
|
||||
// When the browser does not support loading ftp resources over
|
||||
// XMLHttpRequest, just reload the page.
|
||||
// NOTE: This will not lead to an infinite redirect loop, because
|
||||
// if the file exists, then the streamsPrivate API will capture the
|
||||
// stream and send back the response. If the stream does not exist,
|
||||
// a "Webpage not available" error will be shown (not the PDF Viewer).
|
||||
location.replace(file);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (/^filesystem:/.test(file) && !pdfjsLib.PDFJS.disableWorker) {
|
||||
// The security origin of filesystem:-URLs are not preserved when the
|
||||
// URL is passed to a Web worker, (http://crbug.com/362061), so we have
|
||||
// to create an intermediate blob:-URL as a work-around.
|
||||
var resolveLocalFileSystemURL = window.resolveLocalFileSystemURL ||
|
||||
window.webkitResolveLocalFileSystemURL;
|
||||
resolveLocalFileSystemURL(file, function onResolvedFSURL(fileEntry) {
|
||||
fileEntry.file(function(fileObject) {
|
||||
var blobUrl = URL.createObjectURL(fileObject);
|
||||
callback(blobUrl, fileObject.size);
|
||||
});
|
||||
}, function onFileSystemError(error) {
|
||||
// This should not happen. When it happens, just fall back to the
|
||||
// usual way of getting the File's data (via the Web worker).
|
||||
console.warn('Cannot resolve file ' + file + ', ' + error.name + ' ' +
|
||||
error.message);
|
||||
callback(file);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (/^https?:/.test(file)) {
|
||||
// Assumption: The file being opened is the file that was requested.
|
||||
// There is no UI to input a different URL, so this assumption will hold
|
||||
// for now.
|
||||
setReferer(file, function() {
|
||||
callback(file);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (/^file?:/.test(file)) {
|
||||
getEmbedderOrigin(function(origin) {
|
||||
// If the origin cannot be determined, let Chrome decide whether to
|
||||
// allow embedding files. Otherwise, only allow local files to be
|
||||
// embedded from local files or Chrome extensions.
|
||||
// Even without this check, the file load in frames is still blocked,
|
||||
// but this may change in the future (https://crbug.com/550151).
|
||||
if (origin && !/^file:|^chrome-extension:/.test(origin)) {
|
||||
PDFViewerApplication.error('Blocked ' + origin + ' from loading ' +
|
||||
file + '. Refused to load a local file in a non-local page ' +
|
||||
'for security reasons.');
|
||||
return;
|
||||
isAllowedFileSchemeAccess(function(isAllowedAccess) {
|
||||
if (isAllowedAccess) {
|
||||
callback(file);
|
||||
} else {
|
||||
requestAccessToLocalFile(file);
|
||||
}
|
||||
isAllowedFileSchemeAccess(function(isAllowedAccess) {
|
||||
if (isAllowedAccess) {
|
||||
callback(file);
|
||||
} else {
|
||||
requestAccessToLocalFile(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
callback(file);
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
callback(file);
|
||||
};
|
||||
|
||||
function getEmbedderOrigin(callback) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue