Skip to content

Commit babd8df

Browse files
committed
Un-inline pdf.js for the extension/mozcentral and remove fetch pdf by content code.
1 parent 3c5a9ba commit babd8df

File tree

5 files changed

+25
-68
lines changed

5 files changed

+25
-68
lines changed

extensions/firefox/components/PdfStreamConverter.js

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -544,21 +544,6 @@ PdfStreamConverter.prototype = {
544544
if (!isEnabled())
545545
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
546546

547-
var useFetchByChrome = getBoolPref(PREF_PREFIX + '.fetchByChrome', true);
548-
if (!useFetchByChrome) {
549-
// Ignoring HTTP POST requests -- pdf.js has to repeat the request.
550-
var skipConversion = false;
551-
try {
552-
var request = aCtxt;
553-
request.QueryInterface(Ci.nsIHttpChannel);
554-
skipConversion = (request.requestMethod !== 'GET');
555-
} catch (e) {
556-
// Non-HTTP request... continue normally.
557-
}
558-
if (skipConversion)
559-
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
560-
}
561-
562547
// Store the listener passed to us
563548
this.listener = aListener;
564549
},
@@ -577,22 +562,15 @@ PdfStreamConverter.prototype = {
577562

578563
// nsIRequestObserver::onStartRequest
579564
onStartRequest: function(aRequest, aContext) {
580-
581565
// Setup the request so we can use it below.
582566
aRequest.QueryInterface(Ci.nsIChannel);
583-
var useFetchByChrome = getBoolPref(PREF_PREFIX + '.fetchByChrome', true);
584-
var dataListener;
585-
if (useFetchByChrome) {
586-
// Creating storage for PDF data
587-
var contentLength = aRequest.contentLength;
588-
dataListener = new PdfDataListener(contentLength);
589-
this.dataListener = dataListener;
590-
this.binaryStream = Cc['@mozilla.org/binaryinputstream;1']
591-
.createInstance(Ci.nsIBinaryInputStream);
592-
} else {
593-
// Cancel the request so the viewer can handle it.
594-
aRequest.cancel(Cr.NS_BINDING_ABORTED);
595-
}
567+
// Creating storage for PDF data
568+
var contentLength = aRequest.contentLength;
569+
var dataListener = new PdfDataListener(contentLength);
570+
this.dataListener = dataListener;
571+
this.binaryStream = Cc['@mozilla.org/binaryinputstream;1']
572+
.createInstance(Ci.nsIBinaryInputStream);
573+
596574
// Change the content type so we don't get stuck in a loop.
597575
aRequest.contentType = 'text/html';
598576

@@ -642,19 +620,17 @@ PdfStreamConverter.prototype = {
642620
channel.originalURI = aRequest.URI;
643621
channel.loadGroup = aRequest.loadGroup;
644622

645-
if (useFetchByChrome) {
646-
// We can use resource principal when data is fetched by the chrome
647-
// e.g. useful for NoScript
648-
var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1']
649-
.getService(Ci.nsIScriptSecurityManager);
650-
var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null);
651-
// FF16 and below had getCodebasePrincipal, it was replaced by
652-
// getNoAppCodebasePrincipal (bug 758258).
653-
var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ?
654-
securityManager.getNoAppCodebasePrincipal(uri) :
655-
securityManager.getCodebasePrincipal(uri);
656-
aRequest.owner = resourcePrincipal;
657-
}
623+
// We can use resource principal when data is fetched by the chrome
624+
// e.g. useful for NoScript
625+
var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1']
626+
.getService(Ci.nsIScriptSecurityManager);
627+
var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null);
628+
// FF16 and below had getCodebasePrincipal, it was replaced by
629+
// getNoAppCodebasePrincipal (bug 758258).
630+
var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ?
631+
securityManager.getNoAppCodebasePrincipal(uri) :
632+
securityManager.getCodebasePrincipal(uri);
633+
aRequest.owner = resourcePrincipal;
658634
channel.asyncOpen(proxy, aContext);
659635
},
660636

make.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ target.firefox = function() {
354354
FIREFOX_BUILD_CONTENT_DIR + '/web']
355355
],
356356
preprocess: [
357-
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web']
357+
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
358+
[BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR + BUILD_TARGET]
358359
]
359360
};
360361
builder.build(setup);
@@ -462,7 +463,8 @@ target.mozcentral = function() {
462463
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
463464
],
464465
preprocess: [
465-
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web']
466+
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
467+
[BUILD_TARGET, MOZCENTRAL_CONTENT_DIR + BUILD_TARGET]
466468
]
467469
};
468470
builder.build(setup);

src/api.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -456,19 +456,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
456456
}
457457

458458
try {
459-
var worker;
460-
//#if !(FIREFOX || MOZCENTRAL)
461459
// Some versions of FF can't create a worker on localhost, see:
462460
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280
463-
worker = new Worker(workerSrc);
464-
//#else
465-
// // The firefox extension can't load the worker from the resource://
466-
// // url so we have to inline the script and then use the blob loader.
467-
// var script = document.querySelector('#PDFJS_SCRIPT_TAG');
468-
// var blob = PDFJS.createBlob(script.textContent, script.type);
469-
// var blobUrl = window.URL.createObjectURL(blob);
470-
// worker = new Worker(blobUrl);
471-
//#endif
461+
var worker = new Worker(workerSrc);
472462
var messageHandler = new MessageHandler('main', worker);
473463
this.messageHandler = messageHandler;
474464

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
<!-- This snippet is used in firefox extension, see Makefile -->
22
<base href="resource://pdf.js/web/" />
33
<script type="text/javascript" src="l10n.js"></script>
4-
<script type="text/javascript" id="PDFJS_SCRIPT_TAG">
5-
<!--
6-
// pdf.js is inlined here because resource:// urls won't work
7-
// for loading workers.
8-
//#include ../build/pdf.js
9-
-->
10-
</script>
11-
<script type="text/javascript">
12-
// This specifies the location of the pdf.js file.
13-
PDFJS.isFirefoxExtension = true;
14-
PDFJS.workerSrc = 'none';
15-
</script>
4+
<script type="text/javascript" src="../build/pdf.js"></script>

web/viewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var FindStates = {
4444

4545
var ANNOT_MIN_SIZE = 10;
4646

47-
//#if (GENERIC || CHROME)
47+
//#if (FIREFOX || MOZCENTRAL || B2G || GENERIC || CHROME)
4848
//PDFJS.workerSrc = '../build/pdf.js';
4949
//#endif
5050

0 commit comments

Comments
 (0)