Refactors firefoxcom dependency on app and l10n.
This commit is contained in:
parent
81fc46e666
commit
148102b626
@ -1,14 +1,14 @@
|
|||||||
/* globals FirefoxCom */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Small subset of the webL10n API by Fabien Cazenave for pdf.js extension.
|
// Small subset of the webL10n API by Fabien Cazenave for pdf.js extension.
|
||||||
(function(window) {
|
(function(window) {
|
||||||
var gLanguage = '';
|
var gLanguage = '';
|
||||||
|
var gExternalLocalizerServices = null;
|
||||||
|
|
||||||
// fetch an l10n objects
|
// fetch an l10n objects
|
||||||
function getL10nData(key) {
|
function getL10nData(key) {
|
||||||
var response = FirefoxCom.requestSync('getStrings', key);
|
var response = gExternalLocalizerServices.getStrings(key);
|
||||||
var data = JSON.parse(response);
|
var data = JSON.parse(response);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
console.warn('[l10n] #' + key + ' missing for [' + gLanguage + ']');
|
console.warn('[l10n] #' + key + ' missing for [' + gLanguage + ']');
|
||||||
@ -94,8 +94,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
function translateDocument() {
|
||||||
gLanguage = FirefoxCom.requestSync('getLocale', null);
|
gLanguage = gExternalLocalizerServices.getLocale();
|
||||||
|
|
||||||
translateFragment();
|
translateFragment();
|
||||||
|
|
||||||
@ -104,6 +104,13 @@
|
|||||||
evtObject.initEvent('localized', false, false);
|
evtObject.initEvent('localized', false, false);
|
||||||
evtObject.language = gLanguage;
|
evtObject.language = gLanguage;
|
||||||
window.dispatchEvent(evtObject);
|
window.dispatchEvent(evtObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('DOMContentLoaded', function() {
|
||||||
|
if (gExternalLocalizerServices) {
|
||||||
|
translateDocument();
|
||||||
|
}
|
||||||
|
// ... else see setExternalLocalizerServices below
|
||||||
});
|
});
|
||||||
|
|
||||||
// Public API
|
// Public API
|
||||||
@ -128,6 +135,16 @@
|
|||||||
return (rtlList.indexOf(shortCode) >= 0) ? 'rtl' : 'ltr';
|
return (rtlList.indexOf(shortCode) >= 0) ? 'rtl' : 'ltr';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setExternalLocalizerServices: function (externalLocalizerServices) {
|
||||||
|
gExternalLocalizerServices = externalLocalizerServices;
|
||||||
|
|
||||||
|
// ... in case if we missed DOMContentLoaded above.
|
||||||
|
if (window.document.readyState === 'interactive' ||
|
||||||
|
window.document.readyState === 'complete') {
|
||||||
|
translateDocument();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// translate an element or document fragment
|
// translate an element or document fragment
|
||||||
translate: translateFragment
|
translate: translateFragment
|
||||||
};
|
};
|
||||||
|
198
web/app.js
198
web/app.js
@ -19,8 +19,8 @@
|
|||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
define('pdfjs-web/app', ['exports', 'pdfjs-web/ui_utils',
|
define('pdfjs-web/app', ['exports', 'pdfjs-web/ui_utils',
|
||||||
'pdfjs-web/firefoxcom', 'pdfjs-web/download_manager',
|
'pdfjs-web/download_manager', 'pdfjs-web/pdf_history',
|
||||||
'pdfjs-web/pdf_history', 'pdfjs-web/preferences', 'pdfjs-web/pdf_sidebar',
|
'pdfjs-web/preferences', 'pdfjs-web/pdf_sidebar',
|
||||||
'pdfjs-web/view_history', 'pdfjs-web/pdf_thumbnail_viewer',
|
'pdfjs-web/view_history', 'pdfjs-web/pdf_thumbnail_viewer',
|
||||||
'pdfjs-web/secondary_toolbar', 'pdfjs-web/password_prompt',
|
'pdfjs-web/secondary_toolbar', 'pdfjs-web/password_prompt',
|
||||||
'pdfjs-web/pdf_presentation_mode', 'pdfjs-web/pdf_document_properties',
|
'pdfjs-web/pdf_presentation_mode', 'pdfjs-web/pdf_document_properties',
|
||||||
@ -32,12 +32,11 @@
|
|||||||
'pdfjs-web/pdfjs'],
|
'pdfjs-web/pdfjs'],
|
||||||
factory);
|
factory);
|
||||||
} else if (typeof exports !== 'undefined') {
|
} else if (typeof exports !== 'undefined') {
|
||||||
factory(exports, require('./ui_utils.js'), require('./firefoxcom.js'),
|
factory(exports, require('./ui_utils.js'), require('./download_manager.js'),
|
||||||
require('./download_manager.js'), require('./pdf_history.js'),
|
require('./pdf_history.js'), require('./preferences.js'),
|
||||||
require('./preferences.js'), require('./pdf_sidebar.js'),
|
require('./pdf_sidebar.js'), require('./view_history.js'),
|
||||||
require('./view_history.js'), require('./pdf_thumbnail_viewer.js'),
|
require('./pdf_thumbnail_viewer.js'), require('./secondary_toolbar.js'),
|
||||||
require('./secondary_toolbar.js'), require('./password_prompt.js'),
|
require('./password_prompt.js'), require('./pdf_presentation_mode.js'),
|
||||||
require('./pdf_presentation_mode.js'),
|
|
||||||
require('./pdf_document_properties.js'), require('./hand_tool.js'),
|
require('./pdf_document_properties.js'), require('./hand_tool.js'),
|
||||||
require('./pdf_viewer.js'), require('./pdf_rendering_queue.js'),
|
require('./pdf_viewer.js'), require('./pdf_rendering_queue.js'),
|
||||||
require('./pdf_link_service.js'), require('./pdf_outline_viewer.js'),
|
require('./pdf_link_service.js'), require('./pdf_outline_viewer.js'),
|
||||||
@ -46,20 +45,20 @@
|
|||||||
require('./mozPrintCallback_polyfill.js'), require('./pdfjs.js'));
|
require('./mozPrintCallback_polyfill.js'), require('./pdfjs.js'));
|
||||||
} else {
|
} else {
|
||||||
factory((root.pdfjsWebApp = {}), root.pdfjsWebUIUtils,
|
factory((root.pdfjsWebApp = {}), root.pdfjsWebUIUtils,
|
||||||
root.pdfjsWebFirefoxCom, root.pdfjsWebDownloadManager,
|
root.pdfjsWebDownloadManager, root.pdfjsWebPDFHistory,
|
||||||
root.pdfjsWebPDFHistory, root.pdfjsWebPreferences,
|
root.pdfjsWebPreferences, root.pdfjsWebPDFSidebar,
|
||||||
root.pdfjsWebPDFSidebar, root.pdfjsWebViewHistory,
|
root.pdfjsWebViewHistory, root.pdfjsWebPDFThumbnailViewer,
|
||||||
root.pdfjsWebPDFThumbnailViewer, root.pdfjsWebSecondaryToolbar,
|
root.pdfjsWebSecondaryToolbar, root.pdfjsWebPasswordPrompt,
|
||||||
root.pdfjsWebPasswordPrompt, root.pdfjsWebPDFPresentationMode,
|
root.pdfjsWebPDFPresentationMode, root.pdfjsWebPDFDocumentProperties,
|
||||||
root.pdfjsWebPDFDocumentProperties, root.pdfjsWebHandTool,
|
root.pdfjsWebHandTool, root.pdfjsWebPDFViewer,
|
||||||
root.pdfjsWebPDFViewer, root.pdfjsWebPDFRenderingQueue,
|
root.pdfjsWebPDFRenderingQueue, root.pdfjsWebPDFLinkService,
|
||||||
root.pdfjsWebPDFLinkService, root.pdfjsWebPDFOutlineViewer,
|
root.pdfjsWebPDFOutlineViewer, root.pdfjsWebOverlayManager,
|
||||||
root.pdfjsWebOverlayManager, root.pdfjsWebPDFAttachmentViewer,
|
root.pdfjsWebPDFAttachmentViewer, root.pdfjsWebPDFFindController,
|
||||||
root.pdfjsWebPDFFindController, root.pdfjsWebPDFFindBar,
|
root.pdfjsWebPDFFindBar, root.pdfjsWebMozPrintCallbackPolyfill,
|
||||||
root.pdfjsWebMozPrintCallbackPolyfill, root.pdfjsWebPDFJS);
|
root.pdfjsWebPDFJS);
|
||||||
}
|
}
|
||||||
}(this, function (exports, uiUtilsLib, firefoxComLib, downloadManagerLib,
|
}(this, function (exports, uiUtilsLib, downloadManagerLib, pdfHistoryLib,
|
||||||
pdfHistoryLib, preferencesLib, pdfSidebarLib, viewHistoryLib,
|
preferencesLib, pdfSidebarLib, viewHistoryLib,
|
||||||
pdfThumbnailViewerLib, secondaryToolbarLib, passwordPromptLib,
|
pdfThumbnailViewerLib, secondaryToolbarLib, passwordPromptLib,
|
||||||
pdfPresentationModeLib, pdfDocumentPropertiesLib, handToolLib,
|
pdfPresentationModeLib, pdfDocumentPropertiesLib, handToolLib,
|
||||||
pdfViewerLib, pdfRenderingQueueLib, pdfLinkServiceLib,
|
pdfViewerLib, pdfRenderingQueueLib, pdfLinkServiceLib,
|
||||||
@ -67,7 +66,6 @@
|
|||||||
pdfAttachmentViewerLib, pdfFindControllerLib, pdfFindBarLib,
|
pdfAttachmentViewerLib, pdfFindControllerLib, pdfFindBarLib,
|
||||||
mozPrintCallbackPolyfillLib, pdfjsLib) {
|
mozPrintCallbackPolyfillLib, pdfjsLib) {
|
||||||
|
|
||||||
var FirefoxCom = firefoxComLib.FirefoxCom;
|
|
||||||
var UNKNOWN_SCALE = uiUtilsLib.UNKNOWN_SCALE;
|
var UNKNOWN_SCALE = uiUtilsLib.UNKNOWN_SCALE;
|
||||||
var DEFAULT_SCALE_VALUE = uiUtilsLib.DEFAULT_SCALE_VALUE;
|
var DEFAULT_SCALE_VALUE = uiUtilsLib.DEFAULT_SCALE_VALUE;
|
||||||
var ProgressBar = uiUtilsLib.ProgressBar;
|
var ProgressBar = uiUtilsLib.ProgressBar;
|
||||||
@ -75,8 +73,6 @@ var getPDFFileNameFromURL = uiUtilsLib.getPDFFileNameFromURL;
|
|||||||
var noContextMenuHandler = uiUtilsLib.noContextMenuHandler;
|
var noContextMenuHandler = uiUtilsLib.noContextMenuHandler;
|
||||||
var mozL10n = uiUtilsLib.mozL10n;
|
var mozL10n = uiUtilsLib.mozL10n;
|
||||||
var parseQueryString = uiUtilsLib.parseQueryString;
|
var parseQueryString = uiUtilsLib.parseQueryString;
|
||||||
var DownloadManager = downloadManagerLib.DownloadManager ||
|
|
||||||
firefoxComLib.DownloadManager;
|
|
||||||
var PDFHistory = pdfHistoryLib.PDFHistory;
|
var PDFHistory = pdfHistoryLib.PDFHistory;
|
||||||
var Preferences = preferencesLib.Preferences;
|
var Preferences = preferencesLib.Preferences;
|
||||||
var SidebarView = pdfSidebarLib.SidebarView;
|
var SidebarView = pdfSidebarLib.SidebarView;
|
||||||
@ -122,6 +118,23 @@ function configure(PDFJS) {
|
|||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DefaultExernalServices = {
|
||||||
|
updateFindControlState: function (data) {},
|
||||||
|
initPassiveLoading: function (callbacks) {},
|
||||||
|
fallback: function (data, callback) {},
|
||||||
|
reportTelemetry: function (data) {},
|
||||||
|
createDownloadManager: function () {
|
||||||
|
return new downloadManagerLib.DownloadManager();
|
||||||
|
},
|
||||||
|
supportsIntegratedFind: false,
|
||||||
|
supportsDocumentFonts: true,
|
||||||
|
supportsDocumentColors: true,
|
||||||
|
supportedMouseWheelZoomModifierKeys: {
|
||||||
|
ctrlKey: true,
|
||||||
|
metaKey: true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var PDFViewerApplication = {
|
var PDFViewerApplication = {
|
||||||
initialBookmark: document.location.hash.substring(1),
|
initialBookmark: document.location.hash.substring(1),
|
||||||
initialDestination: null,
|
initialDestination: null,
|
||||||
@ -153,6 +166,8 @@ var PDFViewerApplication = {
|
|||||||
pdfAttachmentViewer: null,
|
pdfAttachmentViewer: null,
|
||||||
/** @type {ViewHistory} */
|
/** @type {ViewHistory} */
|
||||||
store: null,
|
store: null,
|
||||||
|
/** @type {DownloadManager} */
|
||||||
|
downloadManager: null,
|
||||||
pageRotation: 0,
|
pageRotation: 0,
|
||||||
isInitialViewSet: false,
|
isInitialViewSet: false,
|
||||||
animationStartedPromise: null,
|
animationStartedPromise: null,
|
||||||
@ -162,6 +177,7 @@ var PDFViewerApplication = {
|
|||||||
preferenceDefaultZoomValue: '',
|
preferenceDefaultZoomValue: '',
|
||||||
isViewerEmbedded: (window.parent !== window),
|
isViewerEmbedded: (window.parent !== window),
|
||||||
url: '',
|
url: '',
|
||||||
|
externalServices: DefaultExernalServices,
|
||||||
|
|
||||||
// called once when the document is loaded
|
// called once when the document is loaded
|
||||||
initialize: function pdfViewInitialize(appConfig) {
|
initialize: function pdfViewInitialize(appConfig) {
|
||||||
@ -175,6 +191,9 @@ var PDFViewerApplication = {
|
|||||||
var pdfLinkService = new PDFLinkService();
|
var pdfLinkService = new PDFLinkService();
|
||||||
this.pdfLinkService = pdfLinkService;
|
this.pdfLinkService = pdfLinkService;
|
||||||
|
|
||||||
|
var downloadManager = this.externalServices.createDownloadManager();
|
||||||
|
this.downloadManager = downloadManager;
|
||||||
|
|
||||||
var container = appConfig.mainContainer;
|
var container = appConfig.mainContainer;
|
||||||
var viewer = appConfig.viewerContainer;
|
var viewer = appConfig.viewerContainer;
|
||||||
this.pdfViewer = new PDFViewer({
|
this.pdfViewer = new PDFViewer({
|
||||||
@ -182,7 +201,7 @@ var PDFViewerApplication = {
|
|||||||
viewer: viewer,
|
viewer: viewer,
|
||||||
renderingQueue: pdfRenderingQueue,
|
renderingQueue: pdfRenderingQueue,
|
||||||
linkService: pdfLinkService,
|
linkService: pdfLinkService,
|
||||||
downloadManager: new DownloadManager()
|
downloadManager: downloadManager
|
||||||
});
|
});
|
||||||
pdfRenderingQueue.setViewer(this.pdfViewer);
|
pdfRenderingQueue.setViewer(this.pdfViewer);
|
||||||
pdfLinkService.setViewer(this.pdfViewer);
|
pdfLinkService.setViewer(this.pdfViewer);
|
||||||
@ -214,7 +233,7 @@ var PDFViewerApplication = {
|
|||||||
}.bind(this);
|
}.bind(this);
|
||||||
this.findController.onUpdateState = function (state, previous, matchCount) {
|
this.findController.onUpdateState = function (state, previous, matchCount) {
|
||||||
if (this.supportsIntegratedFind) {
|
if (this.supportsIntegratedFind) {
|
||||||
FirefoxCom.request('updateFindControlState',
|
this.externalServices.updateFindControlState(
|
||||||
{result: state, findPrevious: previous});
|
{result: state, findPrevious: previous});
|
||||||
} else {
|
} else {
|
||||||
this.findBar.updateUIState(state, previous, matchCount);
|
this.findBar.updateUIState(state, previous, matchCount);
|
||||||
@ -270,7 +289,7 @@ var PDFViewerApplication = {
|
|||||||
|
|
||||||
this.pdfAttachmentViewer = new PDFAttachmentViewer({
|
this.pdfAttachmentViewer = new PDFAttachmentViewer({
|
||||||
container: appConfig.sidebar.attachmentsView,
|
container: appConfig.sidebar.attachmentsView,
|
||||||
downloadManager: new DownloadManager(),
|
downloadManager: downloadManager
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME better PDFSidebar constructor parameters
|
// FIXME better PDFSidebar constructor parameters
|
||||||
@ -411,30 +430,15 @@ var PDFViewerApplication = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get supportsIntegratedFind() {
|
get supportsIntegratedFind() {
|
||||||
var support = false;
|
return this.externalServices.supportsIntegratedFind;
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
|
||||||
// support = FirefoxCom.requestSync('supportsIntegratedFind');
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
return pdfjsLib.shadow(this, 'supportsIntegratedFind', support);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get supportsDocumentFonts() {
|
get supportsDocumentFonts() {
|
||||||
var support = true;
|
return this.externalServices.supportsDocumentFonts;
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
|
||||||
// support = FirefoxCom.requestSync('supportsDocumentFonts');
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
return pdfjsLib.shadow(this, 'supportsDocumentFonts', support);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get supportsDocumentColors() {
|
get supportsDocumentColors() {
|
||||||
var support = true;
|
return this.externalServices.supportsDocumentColors;
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
|
||||||
// support = FirefoxCom.requestSync('supportsDocumentColors');
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
return pdfjsLib.shadow(this, 'supportsDocumentColors', support);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get loadingBar() {
|
get loadingBar() {
|
||||||
@ -444,84 +448,30 @@ var PDFViewerApplication = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get supportedMouseWheelZoomModifierKeys() {
|
get supportedMouseWheelZoomModifierKeys() {
|
||||||
var support = {
|
return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
||||||
ctrlKey: true,
|
|
||||||
metaKey: true,
|
|
||||||
};
|
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
|
||||||
// support = FirefoxCom.requestSync('supportedMouseWheelZoomModifierKeys');
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
return pdfjsLib.shadow(this, 'supportedMouseWheelZoomModifierKeys',
|
|
||||||
support);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
//#if (FIREFOX || MOZCENTRAL)
|
||||||
initPassiveLoading: function pdfViewInitPassiveLoading() {
|
initPassiveLoading: function pdfViewInitPassiveLoading() {
|
||||||
function FirefoxComDataRangeTransport(length, initialData) {
|
this.externalServices.initPassiveLoading({
|
||||||
pdfjsLib.PDFDataRangeTransport.call(this, length, initialData);
|
onOpenWithTransport: function (url, length, transport) {
|
||||||
|
PDFViewerApplication.open(url, {range: transport});
|
||||||
|
|
||||||
|
if (length) {
|
||||||
|
PDFViewerApplication.pdfDocumentProperties.setFileSize(length);
|
||||||
}
|
}
|
||||||
FirefoxComDataRangeTransport.prototype =
|
},
|
||||||
Object.create(pdfjsLib.PDFDataRangeTransport.prototype);
|
onOpenWithData: function (data) {
|
||||||
FirefoxComDataRangeTransport.prototype.requestDataRange =
|
PDFViewerApplication.open(data);
|
||||||
function FirefoxComDataRangeTransport_requestDataRange(begin, end) {
|
},
|
||||||
FirefoxCom.request('requestDataRange', { begin: begin, end: end });
|
onError: function (e) {
|
||||||
};
|
|
||||||
FirefoxComDataRangeTransport.prototype.abort =
|
|
||||||
function FirefoxComDataRangeTransport_abort() {
|
|
||||||
// Sync call to ensure abort is really started.
|
|
||||||
FirefoxCom.requestSync('abortLoading', null);
|
|
||||||
};
|
|
||||||
|
|
||||||
var pdfDataRangeTransport;
|
|
||||||
|
|
||||||
window.addEventListener('message', function windowMessage(e) {
|
|
||||||
if (e.source !== null) {
|
|
||||||
// The message MUST originate from Chrome code.
|
|
||||||
console.warn('Rejected untrusted message from ' + e.origin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var args = e.data;
|
|
||||||
|
|
||||||
if (typeof args !== 'object' || !('pdfjsLoadAction' in args)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (args.pdfjsLoadAction) {
|
|
||||||
case 'supportsRangedLoading':
|
|
||||||
pdfDataRangeTransport =
|
|
||||||
new FirefoxComDataRangeTransport(args.length, args.data);
|
|
||||||
|
|
||||||
PDFViewerApplication.open(args.pdfUrl,
|
|
||||||
{range: pdfDataRangeTransport});
|
|
||||||
|
|
||||||
if (args.length) {
|
|
||||||
PDFViewerApplication.pdfDocumentProperties
|
|
||||||
.setFileSize(args.length);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'range':
|
|
||||||
pdfDataRangeTransport.onDataRange(args.begin, args.chunk);
|
|
||||||
break;
|
|
||||||
case 'rangeProgress':
|
|
||||||
pdfDataRangeTransport.onDataProgress(args.loaded);
|
|
||||||
break;
|
|
||||||
case 'progressiveRead':
|
|
||||||
pdfDataRangeTransport.onDataProgressiveRead(args.chunk);
|
|
||||||
break;
|
|
||||||
case 'progress':
|
|
||||||
PDFViewerApplication.progress(args.loaded / args.total);
|
|
||||||
break;
|
|
||||||
case 'complete':
|
|
||||||
if (!args.data) {
|
|
||||||
PDFViewerApplication.error(mozL10n.get('loading_error', null,
|
PDFViewerApplication.error(mozL10n.get('loading_error', null,
|
||||||
'An error occurred while loading the PDF.'), e);
|
'An error occurred while loading the PDF.'), e);
|
||||||
break;
|
},
|
||||||
}
|
onProgress: function (loaded, total) {
|
||||||
PDFViewerApplication.open(args.data);
|
PDFViewerApplication.progress(loaded / total);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
FirefoxCom.requestSync('initPassiveLoading', null);
|
|
||||||
},
|
},
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
@ -701,7 +651,7 @@ var PDFViewerApplication = {
|
|||||||
|
|
||||||
var url = this.url.split('#')[0];
|
var url = this.url.split('#')[0];
|
||||||
var filename = getPDFFileNameFromURL(url);
|
var filename = getPDFFileNameFromURL(url);
|
||||||
var downloadManager = new DownloadManager();
|
var downloadManager = this.downloadManager;
|
||||||
downloadManager.onerror = function (err) {
|
downloadManager.onerror = function (err) {
|
||||||
// This error won't really be helpful because it's likely the
|
// This error won't really be helpful because it's likely the
|
||||||
// fallback won't work either (or is already open).
|
// fallback won't work either (or is already open).
|
||||||
@ -741,7 +691,7 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
this.fellback = true;
|
this.fellback = true;
|
||||||
var url = this.url.split('#')[0];
|
var url = this.url.split('#')[0];
|
||||||
FirefoxCom.request('fallback', { featureId: featureId, url: url },
|
this.externalServices.fallback({ featureId: featureId, url: url },
|
||||||
function response(download) {
|
function response(download) {
|
||||||
if (!download) {
|
if (!download) {
|
||||||
return;
|
return;
|
||||||
@ -1069,12 +1019,12 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
var formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ?
|
var formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ?
|
||||||
'xfa' : 'acroform';
|
'xfa' : 'acroform';
|
||||||
FirefoxCom.request('reportTelemetry', JSON.stringify({
|
self.externalServices.reportTelemetry({
|
||||||
type: 'documentInfo',
|
type: 'documentInfo',
|
||||||
version: versionId,
|
version: versionId,
|
||||||
generator: generatorId,
|
generator: generatorId,
|
||||||
formType: formType
|
formType: formType
|
||||||
}));
|
});
|
||||||
//#endif
|
//#endif
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -1197,9 +1147,9 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
//#endif
|
//#endif
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
//#if (FIREFOX || MOZCENTRAL)
|
||||||
FirefoxCom.request('reportTelemetry', JSON.stringify({
|
this.externalServices.reportTelemetry({
|
||||||
type: 'print'
|
type: 'print'
|
||||||
}));
|
});
|
||||||
//#endif
|
//#endif
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1567,15 +1517,15 @@ document.addEventListener('pagerendered', function (e) {
|
|||||||
}
|
}
|
||||||
//#endif
|
//#endif
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
//#if (FIREFOX || MOZCENTRAL)
|
||||||
FirefoxCom.request('reportTelemetry', JSON.stringify({
|
PDFViewerApplication.externalServices.reportTelemetry({
|
||||||
type: 'pageInfo'
|
type: 'pageInfo'
|
||||||
}));
|
});
|
||||||
// It is a good time to report stream and font types.
|
// It is a good time to report stream and font types.
|
||||||
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
||||||
FirefoxCom.request('reportTelemetry', JSON.stringify({
|
PDFViewerApplication.externalServices.reportTelemetry({
|
||||||
type: 'documentStats',
|
type: 'documentStats',
|
||||||
stats: stats
|
stats: stats
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
//#endif
|
//#endif
|
||||||
}, true);
|
}, true);
|
||||||
|
@ -18,19 +18,18 @@
|
|||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
define('pdfjs-web/firefoxcom', ['exports', 'pdfjs-web/preferences',
|
define('pdfjs-web/firefoxcom', ['exports', 'pdfjs-web/preferences',
|
||||||
'pdfjs-web/pdfjs'], factory);
|
'pdfjs-web/app', 'pdfjs-web/pdfjs'], factory);
|
||||||
} else if (typeof exports !== 'undefined') {
|
} else if (typeof exports !== 'undefined') {
|
||||||
factory(exports, require('./preferences.js'), require('./pdfjs.js'));
|
factory(exports, require('./preferences.js'), require('./app.js'),
|
||||||
|
require('./pdfjs.js'));
|
||||||
} else {
|
} else {
|
||||||
factory((root.pdfjsWebFirefoxCom = {}), root.pdfjsWebPreferences,
|
factory((root.pdfjsWebFirefoxCom = {}), root.pdfjsWebPreferences,
|
||||||
root.pdfjsWebPDFJS);
|
root.pdfjsWebApp, root.pdfjsWebPDFJS);
|
||||||
}
|
}
|
||||||
}(this, function (exports, preferences, pdfjsLib) {
|
}(this, function (exports, preferences, app, pdfjsLib) {
|
||||||
//#if FIREFOX || MOZCENTRAL
|
//#if FIREFOX || MOZCENTRAL
|
||||||
//#if !(FIREFOX || MOZCENTRAL)
|
|
||||||
if (true) { return; } // TODO ensure nothing depends on this module.
|
|
||||||
//#endif
|
|
||||||
var Preferences = preferences.Preferences;
|
var Preferences = preferences.Preferences;
|
||||||
|
var PDFViewerApplication = app.PDFViewerApplication;
|
||||||
|
|
||||||
var FirefoxCom = (function FirefoxComClosure() {
|
var FirefoxCom = (function FirefoxComClosure() {
|
||||||
return {
|
return {
|
||||||
@ -149,6 +148,117 @@ Preferences._readFromStorage = function (prefObj) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function FirefoxComDataRangeTransport(length, initialData) {
|
||||||
|
pdfjsLib.PDFDataRangeTransport.call(this, length, initialData);
|
||||||
|
}
|
||||||
|
FirefoxComDataRangeTransport.prototype =
|
||||||
|
Object.create(pdfjsLib.PDFDataRangeTransport.prototype);
|
||||||
|
FirefoxComDataRangeTransport.prototype.requestDataRange =
|
||||||
|
function FirefoxComDataRangeTransport_requestDataRange(begin, end) {
|
||||||
|
FirefoxCom.request('requestDataRange', { begin: begin, end: end });
|
||||||
|
};
|
||||||
|
FirefoxComDataRangeTransport.prototype.abort =
|
||||||
|
function FirefoxComDataRangeTransport_abort() {
|
||||||
|
// Sync call to ensure abort is really started.
|
||||||
|
FirefoxCom.requestSync('abortLoading', null);
|
||||||
|
};
|
||||||
|
|
||||||
|
PDFViewerApplication.externalServices = {
|
||||||
|
updateFindControlState: function (data) {
|
||||||
|
FirefoxCom.request('updateFindControlState', data);
|
||||||
|
},
|
||||||
|
|
||||||
|
initPassiveLoading: function (callbacks) {
|
||||||
|
var pdfDataRangeTransport;
|
||||||
|
|
||||||
|
window.addEventListener('message', function windowMessage(e) {
|
||||||
|
if (e.source !== null) {
|
||||||
|
// The message MUST originate from Chrome code.
|
||||||
|
console.warn('Rejected untrusted message from ' + e.origin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var args = e.data;
|
||||||
|
|
||||||
|
if (typeof args !== 'object' || !('pdfjsLoadAction' in args)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (args.pdfjsLoadAction) {
|
||||||
|
case 'supportsRangedLoading':
|
||||||
|
pdfDataRangeTransport =
|
||||||
|
new FirefoxComDataRangeTransport(args.length, args.data);
|
||||||
|
|
||||||
|
callbacks.onOpenWithTransport(args.pdfUrl, args.length,
|
||||||
|
pdfDataRangeTransport);
|
||||||
|
break;
|
||||||
|
case 'range':
|
||||||
|
pdfDataRangeTransport.onDataRange(args.begin, args.chunk);
|
||||||
|
break;
|
||||||
|
case 'rangeProgress':
|
||||||
|
pdfDataRangeTransport.onDataProgress(args.loaded);
|
||||||
|
break;
|
||||||
|
case 'progressiveRead':
|
||||||
|
pdfDataRangeTransport.onDataProgressiveRead(args.chunk);
|
||||||
|
break;
|
||||||
|
case 'progress':
|
||||||
|
callbacks.onProgress(args.loaded, args.total);
|
||||||
|
break;
|
||||||
|
case 'complete':
|
||||||
|
if (!args.data) {
|
||||||
|
callbacks.onError(args.errorCode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
callbacks.onOpenWithData(args.data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
FirefoxCom.requestSync('initPassiveLoading', null);
|
||||||
|
},
|
||||||
|
|
||||||
|
fallback: function (data, callback) {
|
||||||
|
FirefoxCom.request('fallback', data, callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
reportTelemetry: function (data) {
|
||||||
|
FirefoxCom.request('reportTelemetry', JSON.stringify(data));
|
||||||
|
},
|
||||||
|
|
||||||
|
createDownloadManager: function () {
|
||||||
|
return new DownloadManager();
|
||||||
|
},
|
||||||
|
|
||||||
|
get supportsIntegratedFind() {
|
||||||
|
var support = FirefoxCom.requestSync('supportsIntegratedFind');
|
||||||
|
return pdfjsLib.shadow(this, 'supportsIntegratedFind', support);
|
||||||
|
},
|
||||||
|
|
||||||
|
get supportsDocumentFonts() {
|
||||||
|
var support = FirefoxCom.requestSync('supportsDocumentFonts');
|
||||||
|
return pdfjsLib.shadow(this, 'supportsDocumentFonts', support);
|
||||||
|
},
|
||||||
|
|
||||||
|
get supportsDocumentColors() {
|
||||||
|
var support = FirefoxCom.requestSync('supportsDocumentColors');
|
||||||
|
return pdfjsLib.shadow(this, 'supportsDocumentColors', support);
|
||||||
|
},
|
||||||
|
|
||||||
|
get supportedMouseWheelZoomModifierKeys() {
|
||||||
|
var support = FirefoxCom.requestSync('supportedMouseWheelZoomModifierKeys');
|
||||||
|
return pdfjsLib.shadow(this, 'supportedMouseWheelZoomModifierKeys',
|
||||||
|
support);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
//// l10n.js for Firefox extension expects services to be set.
|
||||||
|
document.mozL10n.setExternalLocalizerServices({
|
||||||
|
getLocale: function () {
|
||||||
|
return FirefoxCom.requestSync('getLocale', null);
|
||||||
|
},
|
||||||
|
|
||||||
|
getStrings: function (key) {
|
||||||
|
return FirefoxCom.requestSync('getStrings', key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
exports.DownloadManager = DownloadManager;
|
exports.DownloadManager = DownloadManager;
|
||||||
exports.FirefoxCom = FirefoxCom;
|
exports.FirefoxCom = FirefoxCom;
|
||||||
//#endif
|
//#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user