Skip to content

Commit

Permalink
Un-inline pdf.js for the extension/mozcentral and remove fetch pdf by…
Browse files Browse the repository at this point in the history
… content code.
  • Loading branch information
brendandahl committed Oct 29, 2012
1 parent 3c5a9ba commit babd8df
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 68 deletions.
60 changes: 18 additions & 42 deletions extensions/firefox/components/PdfStreamConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand All @@ -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';

Expand Down Expand Up @@ -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);
},

Expand Down
6 changes: 4 additions & 2 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 1 addition & 12 deletions web/viewer-snippet-firefox-extension.html
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit babd8df

Please sign in to comment.