Bug 1754499 - Add pdf.js in GeckoView r=geckoview-reviewers,pdfjs-reviewers,marco,m_kato

Just add the minimal stuff in order to be able to view a pdf in using pdf.js
(whatever the content disposition is).
There are still some things to plug (e.g. find stuff), we must change the UI
and add support for pinch-to-zoom, hence we set the pref pdfjs.disabled to true.

Differential Revision: https://phabricator.services.mozilla.com/D162122
This commit is contained in:
Calixte 2022-11-24 13:36:17 +00:00
parent 5a03842c0f
commit 705175683e
8 changed files with 91 additions and 3 deletions

View File

@ -92,3 +92,10 @@ pref("extensions.formautofill.addresses.capture.enabled", true);
// Debug prefs.
pref("browser.formfill.debug", false);
pref("extensions.formautofill.loglevel", "Warn");
// PDF.js
// Try to convert PDFs sent as octet-stream
pref("pdfjs.handleOctetStream", true);
pref("browser.download.open_pdf_attachments_inline", true);
pref("pdfjs.annotationEditorMode", -1);
pref("pdfjs.disabled", true);

View File

@ -17,6 +17,14 @@ ChromeUtils.defineESModuleGetters(lazy, {
Preferences: "resource://gre/modules/Preferences.sys.mjs",
});
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
XPCOMUtils.defineLazyModuleGetters(lazy, {
PdfJs: "resource://pdf.js/PdfJs.jsm",
});
const { debug, warn } = GeckoViewUtils.initLogging("Startup");
var { DelayedInit } = ChromeUtils.import(
@ -239,6 +247,7 @@ class GeckoViewStartup {
]);
Services.obs.addObserver(this, "browser-idle-startup-tasks-finished");
Services.obs.addObserver(this, "handlersvc-store-initialized");
Services.obs.notifyObservers(null, "geckoview-startup-complete");
break;
@ -253,6 +262,17 @@ class GeckoViewStartup {
Services.startup.trackStartupCrashEnd();
break;
}
case "handlersvc-store-initialized": {
// Initialize PdfJs when running in-process and remote. This only
// happens once since PdfJs registers global hooks. If the PdfJs
// extension is installed the init method below will be overridden
// leaving initialization to the extension.
// parent only: configure default prefs, set up pref observers, register
// pdf content handler, and initializes parent side message manager
// shim for privileged api access.
lazy.PdfJs.init(this._isNewProfile);
break;
}
}
}

View File

@ -114,6 +114,8 @@
@BINPATH@/actors/*
; [Browser Chrome Files]
@BINPATH@/chrome/pdfjs.manifest
@BINPATH@/chrome/pdfjs/*
@BINPATH@/chrome/toolkit@JAREXT@
@BINPATH@/chrome/toolkit.manifest

View File

@ -139,7 +139,9 @@ function getDOMWindow(aChannel, aPrincipal) {
function getActor(window) {
try {
return window.windowGlobalChild.getActor("Pdfjs");
const actorName =
AppConstants.platform === "android" ? "GeckoViewPdfjs" : "Pdfjs";
return window.windowGlobalChild.getActor(actorName);
} catch (ex) {
return null;
}
@ -393,6 +395,10 @@ class ChromeActions {
return Cu.isInAutomation;
}
isMobile() {
return AppConstants.platform === "android";
}
reportTelemetry(data) {
var probeInfo = JSON.parse(data);
switch (probeInfo.type) {

View File

@ -8,6 +8,7 @@ with Files("**"):
BUG_COMPONENT = ("Firefox", "PDF Viewer")
BROWSER_CHROME_MANIFESTS += ["test/browser.ini"]
MOCHITEST_MANIFESTS += ["test/mochitest.ini"]
JAR_MANIFESTS += ["jar.mn"]

View File

@ -0,0 +1,3 @@
[test_pdf_file_in_iframe.html]
support-files =
file_pdfjs_test.pdf

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PDFjs: Load a PDF in an iframe.</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script type="text/javascript">
"use strict";
async function test() {
await SpecialPowers.pushPrefEnv({
"set": [
["pdfjs.disabled", false],
],
});
const iframe = document.createElement("iframe");
document.body.append(iframe);
iframe.src = "file_pdfjs_test.pdf";
iframe.onload = async () => {
const hasViewerContainer = await SpecialPowers.spawn(
iframe.contentWindow,
[],
() => !!this.content.document.getElementById("viewerContainer")
);
ok(
hasViewerContainer,
"The iframe with a pdf must have a `viewerContainer`"
);
SimpleTest.finish();
};
}
window.onload = () => {
SimpleTest.waitForExplicitFinish();
test();
};
</script>
</pre>
</body>
</html>

View File

@ -373,7 +373,7 @@ HandlerService.prototype = {
Services.prefs.getBoolPref(
"browser.download.improvements_to_download_panel"
) &&
!Services.policies.getActivePolicies()?.Handlers &&
!Services.policies?.getActivePolicies()?.Handlers &&
!this._store.data.isDownloadsImprovementsAlreadyMigrated &&
AppConstants.MOZ_APP_NAME != "thunderbird"
) {
@ -409,7 +409,7 @@ HandlerService.prototype = {
Services.prefs.getBoolPref(
"browser.download.improvements_to_download_panel"
) &&
!Services.policies.getActivePolicies()?.Handlers &&
!Services.policies?.getActivePolicies()?.Handlers &&
!this._store.data.isSVGXMLAlreadyMigrated
) {
for (let type of this._noInternalHandlingDefault) {