Browse Source

Enable linting of Firefox specific code in viewer.js

- This patch uncomments a large portion of the Firefox specific code in viewer.js, by using a preprocessor "trick", to enable linting. Doing this actually uncovered some issues, e.g. variables defined multiple times.

 - This patch also fixes a spelling error, `adobe pdfwritter` -> `abobe pdfwriter`, in the `KNOWN_GENERATORS` list used when reporting telemetry data in Firefox.

*Please note:* there's still some Firefox specific code that is commented out, but it's usually just one (or two) lines of code. Hence the risk that errors creep in should be much lower, compared to entire code-blocks.
Jonas Jenwald 10 years ago
parent
commit
91ce16bc1d
  1. 159
      web/viewer.js

159
web/viewer.js

@ -595,21 +595,23 @@ var PDFViewerApplication = {
fallback: function pdfViewFallback(featureId) { fallback: function pdfViewFallback(featureId) {
//#if !(FIREFOX || MOZCENTRAL) //#if !(FIREFOX || MOZCENTRAL)
// return; /* jshint -W027 */
return;
//#else //#else
// // Only trigger the fallback once so we don't spam the user with messages // Only trigger the fallback once so we don't spam the user with messages
// // for one PDF. // for one PDF.
// if (this.fellback) if (this.fellback) {
// return; return;
// this.fellback = true; }
// var url = this.url.split('#')[0]; this.fellback = true;
// FirefoxCom.request('fallback', { featureId: featureId, url: url }, var url = this.url.split('#')[0];
// function response(download) { FirefoxCom.request('fallback', { featureId: featureId, url: url },
// if (!download) { function response(download) {
// return; if (!download) {
// } return;
// PDFViewerApplication.download(); }
// }); PDFViewerApplication.download();
});
//#endif //#endif
}, },
@ -1035,32 +1037,37 @@ var PDFViewerApplication = {
self.fallback(PDFJS.UNSUPPORTED_FEATURES.forms); self.fallback(PDFJS.UNSUPPORTED_FEATURES.forms);
} }
//#if !PRODUCTION
/* jshint -W027 */
return;
//#endif
//#if (FIREFOX || MOZCENTRAL) //#if (FIREFOX || MOZCENTRAL)
// var versionId = String(info.PDFFormatVersion).slice(-1) | 0; var versionId = String(info.PDFFormatVersion).slice(-1) | 0;
// var generatorId = 0; var generatorId = 0;
// var KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwritter", var KNOWN_GENERATORS = [
// "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", 'acrobat distiller', 'acrobat pdfwriter', 'adobe livecycle',
// "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", 'adobe pdf library', 'adobe photoshop', 'ghostscript', 'tcpdf',
// "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", 'cairo', 'dvipdfm', 'dvips', 'pdftex', 'pdfkit', 'itext', 'prince',
// "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"]; 'quarkxpress', 'mac os x', 'microsoft', 'openoffice', 'oracle',
// var generatorId = 0; 'luradocument', 'pdf-xchange', 'antenna house', 'aspose.cells', 'fpdf'
// if (info.Producer) { ];
// KNOWN_GENERATORS.some(function (generator, s, i) { if (info.Producer) {
// if (generator.indexOf(s) < 0) { KNOWN_GENERATORS.some(function (generator, s, i) {
// return false; if (generator.indexOf(s) < 0) {
// } return false;
// generatorId = i + 1; }
// return true; generatorId = i + 1;
// }.bind(null, info.Producer.toLowerCase())); return true;
// } }.bind(null, info.Producer.toLowerCase()));
// var formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ? }
// 'xfa' : 'acroform'; var formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ?
// FirefoxCom.request('reportTelemetry', JSON.stringify({ 'xfa' : 'acroform';
// type: 'documentInfo', FirefoxCom.request('reportTelemetry', JSON.stringify({
// version: versionId, type: 'documentInfo',
// generator: generatorId, version: versionId,
// formType: formType generator: generatorId,
// })); formType: formType
}));
//#endif //#endif
}); });
}, },
@ -1309,10 +1316,14 @@ var PDFViewerApplication = {
this.pdfViewer.getPageView(i).beforePrint(); this.pdfViewer.getPageView(i).beforePrint();
} }
//#if !PRODUCTION
/* jshint -W027 */
return;
//#endif
//#if (FIREFOX || MOZCENTRAL) //#if (FIREFOX || MOZCENTRAL)
// FirefoxCom.request('reportTelemetry', JSON.stringify({ FirefoxCom.request('reportTelemetry', JSON.stringify({
// type: 'print' type: 'print'
// })); }));
//#endif //#endif
}, },
@ -1398,7 +1409,7 @@ function webViewerInitialized() {
//var file = DEFAULT_URL; //var file = DEFAULT_URL;
//#endif //#endif
//#if !(FIREFOX || MOZCENTRAL || CHROME || B2G) //#if GENERIC
var fileInput = document.createElement('input'); var fileInput = document.createElement('input');
fileInput.id = 'fileInput'; fileInput.id = 'fileInput';
fileInput.className = 'fileInput'; fileInput.className = 'fileInput';
@ -1498,11 +1509,11 @@ function webViewerInitialized() {
mozL10n.setLanguage(locale); mozL10n.setLanguage(locale);
//#endif //#endif
//#if (FIREFOX || MOZCENTRAL) //#if (FIREFOX || MOZCENTRAL)
//if (!PDFViewerApplication.supportsDocumentFonts) { if (!PDFViewerApplication.supportsDocumentFonts) {
// PDFJS.disableFontFace = true; PDFJS.disableFontFace = true;
// console.warn(mozL10n.get('web_fonts_disabled', null, console.warn(mozL10n.get('web_fonts_disabled', null,
// 'Web fonts are disabled: unable to use embedded PDF fonts.')); 'Web fonts are disabled: unable to use embedded PDF fonts.'));
//} }
//#endif //#endif
if (!PDFViewerApplication.supportsPrinting) { if (!PDFViewerApplication.supportsPrinting) {
@ -1676,41 +1687,49 @@ document.addEventListener('pagerendered', function (e) {
'An error occurred while rendering the page.'), pageView.error); 'An error occurred while rendering the page.'), pageView.error);
} }
//#if (FIREFOX || MOZCENTRAL)
//FirefoxCom.request('reportTelemetry', JSON.stringify({
// type: 'pageInfo'
//}));
//// It is a good time to report stream and font types
//PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
// FirefoxCom.request('reportTelemetry', JSON.stringify({
// type: 'documentStats',
// stats: stats
// }));
//});
//#endif
// If the page is still visible when it has finished rendering, // If the page is still visible when it has finished rendering,
// ensure that the page number input loading indicator is hidden. // ensure that the page number input loading indicator is hidden.
if (pageNumber === PDFViewerApplication.page) { if (pageNumber === PDFViewerApplication.page) {
var pageNumberInput = document.getElementById('pageNumber'); var pageNumberInput = document.getElementById('pageNumber');
pageNumberInput.classList.remove(PAGE_NUMBER_LOADING_INDICATOR); pageNumberInput.classList.remove(PAGE_NUMBER_LOADING_INDICATOR);
} }
//#if !PRODUCTION
/* jshint -W027 */
return;
//#endif
//#if (FIREFOX || MOZCENTRAL)
FirefoxCom.request('reportTelemetry', JSON.stringify({
type: 'pageInfo'
}));
// It is a good time to report stream and font types.
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
FirefoxCom.request('reportTelemetry', JSON.stringify({
type: 'documentStats',
stats: stats
}));
});
//#endif
}, true); }, true);
document.addEventListener('textlayerrendered', function (e) { document.addEventListener('textlayerrendered', function (e) {
var pageIndex = e.detail.pageNumber - 1; var pageIndex = e.detail.pageNumber - 1;
var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex); var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
//#if !PRODUCTION
/* jshint -W027 */
return;
//#endif
//#if (FIREFOX || MOZCENTRAL) //#if (FIREFOX || MOZCENTRAL)
//if (pageView.textLayer && pageView.textLayer.textDivs && if (pageView.textLayer && pageView.textLayer.textDivs &&
// pageView.textLayer.textDivs.length > 0 && pageView.textLayer.textDivs.length > 0 &&
// !PDFViewerApplication.supportsDocumentColors) { !PDFViewerApplication.supportsDocumentColors) {
// console.error(mozL10n.get('document_colors_disabled', null, console.error(mozL10n.get('document_colors_disabled', null,
// 'PDF documents are not allowed to use their own colors: ' + 'PDF documents are not allowed to use their own colors: ' +
// '\'Allow pages to choose their own colors\' ' + '\'Allow pages to choose their own colors\' ' +
// 'is deactivated in the browser.')); 'is deactivated in the browser.'));
// PDFViewerApplication.fallback(); PDFViewerApplication.fallback();
//} }
//#endif //#endif
}, true); }, true);

Loading…
Cancel
Save