Merge pull request #2327 from brendandahl/un-inline
Un-inline pdf.js for the extension/mozcentral and remove fetch pdf by content code.
This commit is contained in:
commit
b47e4b8855
@ -544,21 +544,6 @@ PdfStreamConverter.prototype = {
|
|||||||
if (!isEnabled())
|
if (!isEnabled())
|
||||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
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
|
// Store the listener passed to us
|
||||||
this.listener = aListener;
|
this.listener = aListener;
|
||||||
},
|
},
|
||||||
@ -577,22 +562,15 @@ PdfStreamConverter.prototype = {
|
|||||||
|
|
||||||
// nsIRequestObserver::onStartRequest
|
// nsIRequestObserver::onStartRequest
|
||||||
onStartRequest: function(aRequest, aContext) {
|
onStartRequest: function(aRequest, aContext) {
|
||||||
|
|
||||||
// Setup the request so we can use it below.
|
// Setup the request so we can use it below.
|
||||||
aRequest.QueryInterface(Ci.nsIChannel);
|
aRequest.QueryInterface(Ci.nsIChannel);
|
||||||
var useFetchByChrome = getBoolPref(PREF_PREFIX + '.fetchByChrome', true);
|
// Creating storage for PDF data
|
||||||
var dataListener;
|
var contentLength = aRequest.contentLength;
|
||||||
if (useFetchByChrome) {
|
var dataListener = new PdfDataListener(contentLength);
|
||||||
// Creating storage for PDF data
|
this.dataListener = dataListener;
|
||||||
var contentLength = aRequest.contentLength;
|
this.binaryStream = Cc['@mozilla.org/binaryinputstream;1']
|
||||||
dataListener = new PdfDataListener(contentLength);
|
.createInstance(Ci.nsIBinaryInputStream);
|
||||||
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);
|
|
||||||
}
|
|
||||||
// Change the content type so we don't get stuck in a loop.
|
// Change the content type so we don't get stuck in a loop.
|
||||||
aRequest.contentType = 'text/html';
|
aRequest.contentType = 'text/html';
|
||||||
|
|
||||||
@ -642,19 +620,17 @@ PdfStreamConverter.prototype = {
|
|||||||
channel.originalURI = aRequest.URI;
|
channel.originalURI = aRequest.URI;
|
||||||
channel.loadGroup = aRequest.loadGroup;
|
channel.loadGroup = aRequest.loadGroup;
|
||||||
|
|
||||||
if (useFetchByChrome) {
|
// We can use resource principal when data is fetched by the chrome
|
||||||
// We can use resource principal when data is fetched by the chrome
|
// e.g. useful for NoScript
|
||||||
// e.g. useful for NoScript
|
var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1']
|
||||||
var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1']
|
.getService(Ci.nsIScriptSecurityManager);
|
||||||
.getService(Ci.nsIScriptSecurityManager);
|
var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null);
|
||||||
var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null);
|
// FF16 and below had getCodebasePrincipal, it was replaced by
|
||||||
// FF16 and below had getCodebasePrincipal, it was replaced by
|
// getNoAppCodebasePrincipal (bug 758258).
|
||||||
// getNoAppCodebasePrincipal (bug 758258).
|
var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ?
|
||||||
var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ?
|
securityManager.getNoAppCodebasePrincipal(uri) :
|
||||||
securityManager.getNoAppCodebasePrincipal(uri) :
|
securityManager.getCodebasePrincipal(uri);
|
||||||
securityManager.getCodebasePrincipal(uri);
|
aRequest.owner = resourcePrincipal;
|
||||||
aRequest.owner = resourcePrincipal;
|
|
||||||
}
|
|
||||||
channel.asyncOpen(proxy, aContext);
|
channel.asyncOpen(proxy, aContext);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
6
make.js
6
make.js
@ -354,7 +354,8 @@ target.firefox = function() {
|
|||||||
FIREFOX_BUILD_CONTENT_DIR + '/web']
|
FIREFOX_BUILD_CONTENT_DIR + '/web']
|
||||||
],
|
],
|
||||||
preprocess: [
|
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);
|
builder.build(setup);
|
||||||
@ -462,7 +463,8 @@ target.mozcentral = function() {
|
|||||||
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
|
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
|
||||||
],
|
],
|
||||||
preprocess: [
|
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);
|
builder.build(setup);
|
||||||
|
12
src/api.js
12
src/api.js
@ -456,19 +456,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var worker;
|
|
||||||
//#if !(FIREFOX || MOZCENTRAL)
|
|
||||||
// Some versions of FF can't create a worker on localhost, see:
|
// Some versions of FF can't create a worker on localhost, see:
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280
|
||||||
worker = new Worker(workerSrc);
|
var 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 messageHandler = new MessageHandler('main', worker);
|
var messageHandler = new MessageHandler('main', worker);
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
|
|
||||||
|
@ -1,15 +1,4 @@
|
|||||||
<!-- This snippet is used in firefox extension, see Makefile -->
|
<!-- This snippet is used in firefox extension, see Makefile -->
|
||||||
<base href="resource://pdf.js/web/" />
|
<base href="resource://pdf.js/web/" />
|
||||||
<script type="text/javascript" src="l10n.js"></script>
|
<script type="text/javascript" src="l10n.js"></script>
|
||||||
<script type="text/javascript" id="PDFJS_SCRIPT_TAG">
|
<script type="text/javascript" src="../build/pdf.js"></script>
|
||||||
<!--
|
|
||||||
// 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>
|
|
||||||
|
@ -44,7 +44,7 @@ var FindStates = {
|
|||||||
|
|
||||||
var ANNOT_MIN_SIZE = 10;
|
var ANNOT_MIN_SIZE = 10;
|
||||||
|
|
||||||
//#if (GENERIC || CHROME)
|
//#if (FIREFOX || MOZCENTRAL || B2G || GENERIC || CHROME)
|
||||||
//PDFJS.workerSrc = '../build/pdf.js';
|
//PDFJS.workerSrc = '../build/pdf.js';
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user