mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #1943 from yurydelendik/loadingbychrome
Implements loading PDF data by extension/chrome
This commit is contained in:
commit
e11e8117c5
2 changed files with 199 additions and 23 deletions
|
@ -348,11 +348,42 @@ var PDFView = {
|
|||
return support;
|
||||
},
|
||||
|
||||
initPassiveLoading: function pdfViewInitPassiveLoading() {
|
||||
if (!PDFView.loadingBar) {
|
||||
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
|
||||
}
|
||||
|
||||
window.addEventListener('message', function window_message(e) {
|
||||
var args = e.data;
|
||||
|
||||
if (typeof args !== 'object' || !('pdfjsLoadAction' in args))
|
||||
return;
|
||||
switch (args.pdfjsLoadAction) {
|
||||
case 'progress':
|
||||
PDFView.progress(args.loaded / args.total);
|
||||
break;
|
||||
case 'complete':
|
||||
if (!args.data) {
|
||||
PDFView.error(mozL10n.get('loading_error', null,
|
||||
'An error occurred while loading the PDF.'), e);
|
||||
break;
|
||||
}
|
||||
PDFView.open(args.data, 0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
FirefoxCom.requestSync('initPassiveLoading', null);
|
||||
},
|
||||
|
||||
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
|
||||
this.url = url;
|
||||
document.title = decodeURIComponent(getFileName(url)) || url;
|
||||
},
|
||||
|
||||
open: function pdfViewOpen(url, scale, password) {
|
||||
var parameters = {password: password};
|
||||
if (typeof url === 'string') { // URL
|
||||
this.url = url;
|
||||
document.title = decodeURIComponent(getFileName(url)) || url;
|
||||
this.setTitleUsingUrl(url);
|
||||
parameters.url = url;
|
||||
} else if (url && 'byteLength' in url) { // ArrayBuffer
|
||||
parameters.data = url;
|
||||
|
@ -1768,7 +1799,7 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
|
|||
};
|
||||
};
|
||||
|
||||
window.addEventListener('load', function webViewerLoad(evt) {
|
||||
document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
|
||||
PDFView.initialize();
|
||||
var params = PDFView.parseQueryString(document.location.search.substring(1));
|
||||
|
||||
|
@ -1870,6 +1901,15 @@ window.addEventListener('load', function webViewerLoad(evt) {
|
|||
PDFView.sidebarOpen = outerContainer.classList.contains('sidebarOpen');
|
||||
PDFView.renderHighestPriority();
|
||||
});
|
||||
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
//if (FirefoxCom.requestSync('getLoadingType') == 'passive') {
|
||||
// PDFView.setTitleUsingUrl(file);
|
||||
// PDFView.initPassiveLoading();
|
||||
// return;
|
||||
//}
|
||||
//#endif
|
||||
|
||||
//#if !B2G
|
||||
PDFView.open(file, 0);
|
||||
//#endif
|
||||
|
@ -1961,7 +2001,7 @@ window.addEventListener('change', function webViewerChange(evt) {
|
|||
|
||||
var file = files[0];
|
||||
fileReader.readAsArrayBuffer(file);
|
||||
document.title = file.name;
|
||||
PDFView.setTitleUsingUrl(file.name);
|
||||
|
||||
// URL does not reflect proper document location - hiding some icons.
|
||||
document.getElementById('viewBookmark').setAttribute('hidden', 'true');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue