зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1633270 - view application/octet-stream PDFs in PDF.JS and add a pref to turn this off, r=jaws
Differential Revision: https://phabricator.services.mozilla.com/D75582
This commit is contained in:
Родитель
34a6029cd6
Коммит
998df7c063
|
@ -1372,6 +1372,9 @@ pref("pdfjs.firstRun", true);
|
||||||
pref("pdfjs.previousHandler.preferredAction", 0);
|
pref("pdfjs.previousHandler.preferredAction", 0);
|
||||||
pref("pdfjs.previousHandler.alwaysAskBeforeHandling", false);
|
pref("pdfjs.previousHandler.alwaysAskBeforeHandling", false);
|
||||||
|
|
||||||
|
// Try to convert PDFs sent as octet-stream
|
||||||
|
pref("pdfjs.handleOctetStream", true);
|
||||||
|
|
||||||
// Is the sidebar positioned ahead of the content browser
|
// Is the sidebar positioned ahead of the content browser
|
||||||
pref("sidebar.position_start", true);
|
pref("sidebar.position_start", true);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ Classes = [
|
||||||
'contract_ids': [
|
'contract_ids': [
|
||||||
'@mozilla.org/streamconv;1?from=application/pdf&to=*/*',
|
'@mozilla.org/streamconv;1?from=application/pdf&to=*/*',
|
||||||
'@mozilla.org/streamconv;1?from=application/pdf&to=text/html',
|
'@mozilla.org/streamconv;1?from=application/pdf&to=text/html',
|
||||||
|
'@mozilla.org/streamconv;1?from=application/octet-stream&to=*/*',
|
||||||
|
'@mozilla.org/streamconv;1?from=application/octet-stream&to=text/html',
|
||||||
],
|
],
|
||||||
'jsm': 'resource:///modules/pdfjs.js',
|
'jsm': 'resource:///modules/pdfjs.js',
|
||||||
'constructor': 'StreamConverterFactory',
|
'constructor': 'StreamConverterFactory',
|
||||||
|
|
|
@ -1031,6 +1031,13 @@ PdfStreamConverter.prototype = {
|
||||||
|
|
||||||
// nsIStreamConverter::asyncConvertData
|
// nsIStreamConverter::asyncConvertData
|
||||||
asyncConvertData(aFromType, aToType, aListener, aCtxt) {
|
asyncConvertData(aFromType, aToType, aListener, aCtxt) {
|
||||||
|
if (aCtxt && aCtxt instanceof Ci.nsIChannel) {
|
||||||
|
aCtxt.QueryInterface(Ci.nsIChannel);
|
||||||
|
}
|
||||||
|
// We need to check if we're supposed to convert here, because not all
|
||||||
|
// asyncConvertData consumers will call getConvertedType first:
|
||||||
|
this.getConvertedType(aFromType, aCtxt);
|
||||||
|
|
||||||
// Store the listener passed to us
|
// Store the listener passed to us
|
||||||
this.listener = aListener;
|
this.listener = aListener;
|
||||||
},
|
},
|
||||||
|
@ -1109,13 +1116,32 @@ PdfStreamConverter.prototype = {
|
||||||
|
|
||||||
getConvertedType(aFromType, aChannel) {
|
getConvertedType(aFromType, aChannel) {
|
||||||
const HTML = "text/html";
|
const HTML = "text/html";
|
||||||
|
let channelURI = aChannel?.URI;
|
||||||
|
// We can be invoked for application/octet-stream; check if we want the
|
||||||
|
// channel first:
|
||||||
|
if (aFromType != "application/pdf") {
|
||||||
|
let isPDF = channelURI?.QueryInterface(Ci.nsIURL).fileExtension == "pdf";
|
||||||
|
let typeIsOctetStream = aFromType == "application/octet-stream";
|
||||||
|
if (
|
||||||
|
!isPDF ||
|
||||||
|
!typeIsOctetStream ||
|
||||||
|
!getBoolPref(PREF_PREFIX + ".handleOctetStream", false)
|
||||||
|
) {
|
||||||
|
throw new Components.Exception(
|
||||||
|
"Ignore PDF.js for this download.",
|
||||||
|
Cr.NS_ERROR_FAILURE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// fall through, this appears to be a pdf.
|
||||||
|
}
|
||||||
|
|
||||||
if (this._validateAndMaybeUpdatePDFPrefs()) {
|
if (this._validateAndMaybeUpdatePDFPrefs()) {
|
||||||
return HTML;
|
return HTML;
|
||||||
}
|
}
|
||||||
// Hm, so normally, no pdfjs. However... if this is a file: channel loaded
|
// Hm, so normally, no pdfjs. However... if this is a file: channel loaded
|
||||||
// with system principal, load it anyway:
|
// with system principal, load it anyway:
|
||||||
if (aChannel && aChannel.URI.schemeIs("file")) {
|
if (channelURI?.schemeIs("file")) {
|
||||||
let triggeringPrincipal = aChannel?.loadInfo?.triggeringPrincipal;
|
let triggeringPrincipal = aChannel.loadInfo?.triggeringPrincipal;
|
||||||
if (triggeringPrincipal?.isSystemPrincipal) {
|
if (triggeringPrincipal?.isSystemPrincipal) {
|
||||||
return HTML;
|
return HTML;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,10 @@ support-files =
|
||||||
[browser_pdfjs_force_opening_files.js]
|
[browser_pdfjs_force_opening_files.js]
|
||||||
[browser_pdfjs_main.js]
|
[browser_pdfjs_main.js]
|
||||||
[browser_pdfjs_navigation.js]
|
[browser_pdfjs_navigation.js]
|
||||||
|
[browser_pdfjs_octet_stream.js]
|
||||||
|
support-files =
|
||||||
|
file_pdfjs_object_stream.pdf
|
||||||
|
file_pdfjs_object_stream.pdf^headers^
|
||||||
[browser_pdfjs_savedialog.js]
|
[browser_pdfjs_savedialog.js]
|
||||||
skip-if = verify
|
skip-if = verify
|
||||||
[browser_pdfjs_views.js]
|
[browser_pdfjs_views.js]
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const TESTROOT = getRootDirectory(gTestPath).replace(
|
||||||
|
"chrome://mochitests/content/",
|
||||||
|
"http://mochi.test:8888/"
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that if we open a PDF with octet-stream mimetype, it can load
|
||||||
|
* PDF.js .
|
||||||
|
*/
|
||||||
|
add_task(async function test_octet_stream_opens_pdfjs() {
|
||||||
|
await SpecialPowers.pushPrefEnv({ set: [["pdfjs.handleOctetStream", true]] });
|
||||||
|
// Get a ref to the pdf we want to open.
|
||||||
|
let pdfURL = TESTROOT + "file_pdfjs_object_stream.pdf";
|
||||||
|
|
||||||
|
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
||||||
|
let handlerInfo = mimeService.getFromTypeAndExtension(
|
||||||
|
"application/pdf",
|
||||||
|
"pdf"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Make sure pdf.js is the default handler.
|
||||||
|
is(
|
||||||
|
handlerInfo.alwaysAskBeforeHandling,
|
||||||
|
false,
|
||||||
|
"pdf handler defaults to always-ask is false"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
handlerInfo.preferredAction,
|
||||||
|
Ci.nsIHandlerInfo.handleInternally,
|
||||||
|
"pdf handler defaults to internal"
|
||||||
|
);
|
||||||
|
|
||||||
|
await BrowserTestUtils.withNewTab(
|
||||||
|
{ gBrowser, url: "about:blank" },
|
||||||
|
async function(newTabBrowser) {
|
||||||
|
await waitForPdfJS(newTabBrowser, pdfURL);
|
||||||
|
is(newTabBrowser.currentURI.spec, pdfURL, "Should load pdfjs");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
Двоичный файл не отображается.
|
@ -0,0 +1,2 @@
|
||||||
|
Content-Type: application/octet-stream
|
||||||
|
|
Загрузка…
Ссылка в новой задаче