Un-inline pdf.js for the extension/mozcentral and remove fetch pdf by content code.
This commit is contained in:
parent
3c5a9ba64b
commit
babd8df176
@ -544,21 +544,6 @@ PdfStreamConverter.prototype = {
|
||||
if (!isEnabled())
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
var useFetchByChrome = getBoolPref(PREF_PREFIX + '.fetchByChrome', true);
|
||||
if (!useFetchByChrome) {
|
||||
// Ignoring HTTP POST requests -- pdf.js has to repeat the request.
|
||||
var skipConversion = false;
|
||||
try {
|
||||
var request = aCtxt;
|
||||
request.QueryInterface(Ci.nsIHttpChannel);
|
||||
skipConversion = (request.requestMethod !== 'GET');
|
||||
} catch (e) {
|
||||
// Non-HTTP request... continue normally.
|
||||
}
|
||||
if (skipConversion)
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Store the listener passed to us
|
||||
this.listener = aListener;
|
||||
},
|
||||
@ -577,22 +562,15 @@ PdfStreamConverter.prototype = {
|
||||
|
||||
// nsIRequestObserver::onStartRequest
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
|
||||
// Setup the request so we can use it below.
|
||||
aRequest.QueryInterface(Ci.nsIChannel);
|
||||
var useFetchByChrome = getBoolPref(PREF_PREFIX + '.fetchByChrome', true);
|
||||
var dataListener;
|
||||
if (useFetchByChrome) {
|
||||
// Creating storage for PDF data
|
||||
var contentLength = aRequest.contentLength;
|
||||
dataListener = new PdfDataListener(contentLength);
|
||||
this.dataListener = dataListener;
|
||||
this.binaryStream = Cc['@mozilla.org/binaryinputstream;1']
|
||||
.createInstance(Ci.nsIBinaryInputStream);
|
||||
} else {
|
||||
// Cancel the request so the viewer can handle it.
|
||||
aRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||
}
|
||||
// Creating storage for PDF data
|
||||
var contentLength = aRequest.contentLength;
|
||||
var dataListener = new PdfDataListener(contentLength);
|
||||
this.dataListener = dataListener;
|
||||
this.binaryStream = Cc['@mozilla.org/binaryinputstream;1']
|
||||
.createInstance(Ci.nsIBinaryInputStream);
|
||||
|
||||
// Change the content type so we don't get stuck in a loop.
|
||||
aRequest.contentType = 'text/html';
|
||||
|
||||
@ -642,19 +620,17 @@ PdfStreamConverter.prototype = {
|
||||
channel.originalURI = aRequest.URI;
|
||||
channel.loadGroup = aRequest.loadGroup;
|
||||
|
||||
if (useFetchByChrome) {
|
||||
// We can use resource principal when data is fetched by the chrome
|
||||
// e.g. useful for NoScript
|
||||
var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1']
|
||||
.getService(Ci.nsIScriptSecurityManager);
|
||||
var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null);
|
||||
// FF16 and below had getCodebasePrincipal, it was replaced by
|
||||
// getNoAppCodebasePrincipal (bug 758258).
|
||||
var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ?
|
||||
securityManager.getNoAppCodebasePrincipal(uri) :
|
||||
securityManager.getCodebasePrincipal(uri);
|
||||
aRequest.owner = resourcePrincipal;
|
||||
}
|
||||
// We can use resource principal when data is fetched by the chrome
|
||||
// e.g. useful for NoScript
|
||||
var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1']
|
||||
.getService(Ci.nsIScriptSecurityManager);
|
||||
var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null);
|
||||
// FF16 and below had getCodebasePrincipal, it was replaced by
|
||||
// getNoAppCodebasePrincipal (bug 758258).
|
||||
var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ?
|
||||
securityManager.getNoAppCodebasePrincipal(uri) :
|
||||
securityManager.getCodebasePrincipal(uri);
|
||||
aRequest.owner = resourcePrincipal;
|
||||
channel.asyncOpen(proxy, aContext);
|
||||
},
|
||||
|
||||
|
6
make.js
6
make.js
@ -354,7 +354,8 @@ target.firefox = function() {
|
||||
FIREFOX_BUILD_CONTENT_DIR + '/web']
|
||||
],
|
||||
preprocess: [
|
||||
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web']
|
||||
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
|
||||
[BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR + BUILD_TARGET]
|
||||
]
|
||||
};
|
||||
builder.build(setup);
|
||||
@ -462,7 +463,8 @@ target.mozcentral = function() {
|
||||
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
|
||||
],
|
||||
preprocess: [
|
||||
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web']
|
||||
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
|
||||
[BUILD_TARGET, MOZCENTRAL_CONTENT_DIR + BUILD_TARGET]
|
||||
]
|
||||
};
|
||||
builder.build(setup);
|
||||
|
12
src/api.js
12
src/api.js
@ -456,19 +456,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
||||
}
|
||||
|
||||
try {
|
||||
var worker;
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
// Some versions of FF can't create a worker on localhost, see:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280
|
||||
worker = new Worker(workerSrc);
|
||||
//#else
|
||||
// // The firefox extension can't load the worker from the resource://
|
||||
// // url so we have to inline the script and then use the blob loader.
|
||||
// var script = document.querySelector('#PDFJS_SCRIPT_TAG');
|
||||
// var blob = PDFJS.createBlob(script.textContent, script.type);
|
||||
// var blobUrl = window.URL.createObjectURL(blob);
|
||||
// worker = new Worker(blobUrl);
|
||||
//#endif
|
||||
var worker = new Worker(workerSrc);
|
||||
var messageHandler = new MessageHandler('main', worker);
|
||||
this.messageHandler = messageHandler;
|
||||
|
||||
|
@ -1,15 +1,4 @@
|
||||
<!-- This snippet is used in firefox extension, see Makefile -->
|
||||
<base href="resource://pdf.js/web/" />
|
||||
<script type="text/javascript" src="l10n.js"></script>
|
||||
<script type="text/javascript" id="PDFJS_SCRIPT_TAG">
|
||||
<!--
|
||||
// pdf.js is inlined here because resource:// urls won't work
|
||||
// for loading workers.
|
||||
//#include ../build/pdf.js
|
||||
-->
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
// This specifies the location of the pdf.js file.
|
||||
PDFJS.isFirefoxExtension = true;
|
||||
PDFJS.workerSrc = 'none';
|
||||
</script>
|
||||
<script type="text/javascript" src="../build/pdf.js"></script>
|
||||
|
@ -44,7 +44,7 @@ var FindStates = {
|
||||
|
||||
var ANNOT_MIN_SIZE = 10;
|
||||
|
||||
//#if (GENERIC || CHROME)
|
||||
//#if (FIREFOX || MOZCENTRAL || B2G || GENERIC || CHROME)
|
||||
//PDFJS.workerSrc = '../build/pdf.js';
|
||||
//#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user