|
|
@ -24,7 +24,7 @@ if (typeof PDFJSDev === 'undefined' || |
|
|
|
'FIREFOX and MOZCENTRAL builds.'); |
|
|
|
'FIREFOX and MOZCENTRAL builds.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var FirefoxCom = (function FirefoxComClosure() { |
|
|
|
let FirefoxCom = (function FirefoxComClosure() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates an event that the extension is listening for and will |
|
|
|
* Creates an event that the extension is listening for and will |
|
|
@ -36,17 +36,18 @@ var FirefoxCom = (function FirefoxComClosure() { |
|
|
|
* @return {*} The response. |
|
|
|
* @return {*} The response. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
requestSync(action, data) { |
|
|
|
requestSync(action, data) { |
|
|
|
var request = document.createTextNode(''); |
|
|
|
let request = document.createTextNode(''); |
|
|
|
document.documentElement.appendChild(request); |
|
|
|
document.documentElement.appendChild(request); |
|
|
|
|
|
|
|
|
|
|
|
var sender = document.createEvent('CustomEvent'); |
|
|
|
let sender = document.createEvent('CustomEvent'); |
|
|
|
sender.initCustomEvent('pdf.js.message', true, false, |
|
|
|
sender.initCustomEvent('pdf.js.message', true, false, |
|
|
|
{ action, data, sync: true, }); |
|
|
|
{ action, data, sync: true, }); |
|
|
|
request.dispatchEvent(sender); |
|
|
|
request.dispatchEvent(sender); |
|
|
|
var response = sender.detail.response; |
|
|
|
let response = sender.detail.response; |
|
|
|
document.documentElement.removeChild(request); |
|
|
|
document.documentElement.removeChild(request); |
|
|
|
return response; |
|
|
|
return response; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates an event that the extension is listening for and will |
|
|
|
* Creates an event that the extension is listening for and will |
|
|
|
* asynchronously respond by calling the callback. |
|
|
|
* asynchronously respond by calling the callback. |
|
|
@ -56,11 +57,11 @@ var FirefoxCom = (function FirefoxComClosure() { |
|
|
|
* with one data argument. |
|
|
|
* with one data argument. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
request(action, data, callback) { |
|
|
|
request(action, data, callback) { |
|
|
|
var request = document.createTextNode(''); |
|
|
|
let request = document.createTextNode(''); |
|
|
|
if (callback) { |
|
|
|
if (callback) { |
|
|
|
document.addEventListener('pdf.js.response', function listener(event) { |
|
|
|
document.addEventListener('pdf.js.response', function listener(event) { |
|
|
|
var node = event.target; |
|
|
|
let node = event.target; |
|
|
|
var response = event.detail.response; |
|
|
|
let response = event.detail.response; |
|
|
|
|
|
|
|
|
|
|
|
document.documentElement.removeChild(node); |
|
|
|
document.documentElement.removeChild(node); |
|
|
|
|
|
|
|
|
|
|
@ -70,7 +71,7 @@ var FirefoxCom = (function FirefoxComClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
document.documentElement.appendChild(request); |
|
|
|
document.documentElement.appendChild(request); |
|
|
|
|
|
|
|
|
|
|
|
var sender = document.createEvent('CustomEvent'); |
|
|
|
let sender = document.createEvent('CustomEvent'); |
|
|
|
sender.initCustomEvent('pdf.js.message', true, false, { |
|
|
|
sender.initCustomEvent('pdf.js.message', true, false, { |
|
|
|
action, |
|
|
|
action, |
|
|
|
data, |
|
|
|
data, |
|
|
@ -82,20 +83,16 @@ var FirefoxCom = (function FirefoxComClosure() { |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
var DownloadManager = (function DownloadManagerClosure() { |
|
|
|
class DownloadManager { |
|
|
|
function DownloadManager() {} |
|
|
|
downloadUrl(url, filename) { |
|
|
|
|
|
|
|
|
|
|
|
DownloadManager.prototype = { |
|
|
|
|
|
|
|
downloadUrl: function DownloadManager_downloadUrl(url, filename) { |
|
|
|
|
|
|
|
FirefoxCom.request('download', { |
|
|
|
FirefoxCom.request('download', { |
|
|
|
originalUrl: url, |
|
|
|
originalUrl: url, |
|
|
|
filename, |
|
|
|
filename, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
downloadData: function DownloadManager_downloadData(data, filename, |
|
|
|
downloadData(data, filename, contentType) { |
|
|
|
contentType) { |
|
|
|
let blobUrl = createObjectURL(data, contentType, false); |
|
|
|
var blobUrl = createObjectURL(data, contentType, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FirefoxCom.request('download', { |
|
|
|
FirefoxCom.request('download', { |
|
|
|
blobUrl, |
|
|
|
blobUrl, |
|
|
@ -103,15 +100,15 @@ var DownloadManager = (function DownloadManagerClosure() { |
|
|
|
filename, |
|
|
|
filename, |
|
|
|
isAttachment: true, |
|
|
|
isAttachment: true, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
download: function DownloadManager_download(blob, url, filename) { |
|
|
|
download(blob, url, filename) { |
|
|
|
let blobUrl = window.URL.createObjectURL(blob); |
|
|
|
let blobUrl = URL.createObjectURL(blob); |
|
|
|
let onResponse = (err) => { |
|
|
|
let onResponse = (err) => { |
|
|
|
if (err && this.onerror) { |
|
|
|
if (err && this.onerror) { |
|
|
|
this.onerror(err); |
|
|
|
this.onerror(err); |
|
|
|
} |
|
|
|
} |
|
|
|
window.URL.revokeObjectURL(blobUrl); |
|
|
|
URL.revokeObjectURL(blobUrl); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
FirefoxCom.request('download', { |
|
|
|
FirefoxCom.request('download', { |
|
|
@ -119,11 +116,8 @@ var DownloadManager = (function DownloadManagerClosure() { |
|
|
|
originalUrl: url, |
|
|
|
originalUrl: url, |
|
|
|
filename, |
|
|
|
filename, |
|
|
|
}, onResponse); |
|
|
|
}, onResponse); |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return DownloadManager; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FirefoxPreferences extends BasePreferences { |
|
|
|
class FirefoxPreferences extends BasePreferences { |
|
|
|
_writeToStorage(prefObj) { |
|
|
|
_writeToStorage(prefObj) { |
|
|
@ -134,8 +128,8 @@ class FirefoxPreferences extends BasePreferences { |
|
|
|
|
|
|
|
|
|
|
|
_readFromStorage(prefObj) { |
|
|
|
_readFromStorage(prefObj) { |
|
|
|
return new Promise(function(resolve) { |
|
|
|
return new Promise(function(resolve) { |
|
|
|
FirefoxCom.request('getPreferences', prefObj, function (prefStr) { |
|
|
|
FirefoxCom.request('getPreferences', prefObj, function(prefStr) { |
|
|
|
var readPrefs = JSON.parse(prefStr); |
|
|
|
let readPrefs = JSON.parse(prefStr); |
|
|
|
resolve(readPrefs); |
|
|
|
resolve(readPrefs); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -162,13 +156,13 @@ class MozL10n { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
(function listenFindEvents() { |
|
|
|
(function listenFindEvents() { |
|
|
|
var events = [ |
|
|
|
const events = [ |
|
|
|
'find', |
|
|
|
'find', |
|
|
|
'findagain', |
|
|
|
'findagain', |
|
|
|
'findhighlightallchange', |
|
|
|
'findhighlightallchange', |
|
|
|
'findcasesensitivitychange' |
|
|
|
'findcasesensitivitychange' |
|
|
|
]; |
|
|
|
]; |
|
|
|
var handleEvent = function (evt) { |
|
|
|
let handleEvent = function(evt) { |
|
|
|
if (!PDFViewerApplication.initialized) { |
|
|
|
if (!PDFViewerApplication.initialized) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -183,7 +177,7 @@ class MozL10n { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0, len = events.length; i < len; i++) { |
|
|
|
for (let i = 0, len = events.length; i < len; i++) { |
|
|
|
window.addEventListener(events[i], handleEvent); |
|
|
|
window.addEventListener(events[i], handleEvent); |
|
|
|
} |
|
|
|
} |
|
|
|
})(); |
|
|
|
})(); |
|
|
@ -209,7 +203,7 @@ PDFViewerApplication.externalServices = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
initPassiveLoading(callbacks) { |
|
|
|
initPassiveLoading(callbacks) { |
|
|
|
var pdfDataRangeTransport; |
|
|
|
let pdfDataRangeTransport; |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('message', function windowMessage(e) { |
|
|
|
window.addEventListener('message', function windowMessage(e) { |
|
|
|
if (e.source !== null) { |
|
|
|
if (e.source !== null) { |
|
|
@ -217,7 +211,7 @@ PDFViewerApplication.externalServices = { |
|
|
|
console.warn('Rejected untrusted message from ' + e.origin); |
|
|
|
console.warn('Rejected untrusted message from ' + e.origin); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var args = e.data; |
|
|
|
let args = e.data; |
|
|
|
|
|
|
|
|
|
|
|
if (typeof args !== 'object' || !('pdfjsLoadAction' in args)) { |
|
|
|
if (typeof args !== 'object' || !('pdfjsLoadAction' in args)) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -271,28 +265,28 @@ PDFViewerApplication.externalServices = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
createL10n() { |
|
|
|
createL10n() { |
|
|
|
var mozL10n = document.mozL10n; |
|
|
|
let mozL10n = document.mozL10n; |
|
|
|
// TODO refactor mozL10n.setExternalLocalizerServices
|
|
|
|
// TODO refactor mozL10n.setExternalLocalizerServices
|
|
|
|
return new MozL10n(mozL10n); |
|
|
|
return new MozL10n(mozL10n); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get supportsIntegratedFind() { |
|
|
|
get supportsIntegratedFind() { |
|
|
|
var support = FirefoxCom.requestSync('supportsIntegratedFind'); |
|
|
|
let support = FirefoxCom.requestSync('supportsIntegratedFind'); |
|
|
|
return shadow(this, 'supportsIntegratedFind', support); |
|
|
|
return shadow(this, 'supportsIntegratedFind', support); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get supportsDocumentFonts() { |
|
|
|
get supportsDocumentFonts() { |
|
|
|
var support = FirefoxCom.requestSync('supportsDocumentFonts'); |
|
|
|
let support = FirefoxCom.requestSync('supportsDocumentFonts'); |
|
|
|
return shadow(this, 'supportsDocumentFonts', support); |
|
|
|
return shadow(this, 'supportsDocumentFonts', support); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get supportsDocumentColors() { |
|
|
|
get supportsDocumentColors() { |
|
|
|
var support = FirefoxCom.requestSync('supportsDocumentColors'); |
|
|
|
let support = FirefoxCom.requestSync('supportsDocumentColors'); |
|
|
|
return shadow(this, 'supportsDocumentColors', support); |
|
|
|
return shadow(this, 'supportsDocumentColors', support); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get supportedMouseWheelZoomModifierKeys() { |
|
|
|
get supportedMouseWheelZoomModifierKeys() { |
|
|
|
var support = FirefoxCom.requestSync('supportedMouseWheelZoomModifierKeys'); |
|
|
|
let support = FirefoxCom.requestSync('supportedMouseWheelZoomModifierKeys'); |
|
|
|
return shadow(this, 'supportedMouseWheelZoomModifierKeys', support); |
|
|
|
return shadow(this, 'supportedMouseWheelZoomModifierKeys', support); |
|
|
|
}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|