Skip to content

Commit

Permalink
Thorium patch from mozilla@079eb24
Browse files Browse the repository at this point in the history
  • Loading branch information
panaC committed Nov 27, 2024
1 parent 079eb24 commit 8e914f7
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@
},
"repository": {
"type": "git",
"url": "git://github.com/mozilla/pdf.js.git"
"url": "git://github.com/edrlab/pdf.js.git"
},
"engines": {
"node": ">=20"
"node": ">=22"
},
"scripts": {
"build": "npx gulp web && npx gulp types"
},
"license": "Apache-2.0"
}
111 changes: 85 additions & 26 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ const PDFViewerApplication = {

this._initializedCapability.settled = true;
this._initializedCapability.resolve();
// THORIUM_BUILD
this.eventBus.dispatch("__ready");
},

/**
Expand Down Expand Up @@ -376,15 +378,18 @@ const PDFViewerApplication = {
async _initializeViewerComponents() {
const { appConfig, externalServices, l10n } = this;

const eventBus =
typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")
? new FirefoxEventBus(
AppOptions.get("allowedGlobalEvents"),
externalServices,
AppOptions.get("isInAutomation")
)
: new EventBus();
this.eventBus = AppOptions.eventBus = eventBus;
// THORIUM_BUILD
// const eventBus =
// typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")
// ? new FirefoxEventBus(
// AppOptions.get("allowedGlobalEvents"),
// externalServices,
// AppOptions.get("isInAutomation")
// )
// : new EventBus();
console.log("PDFJS EVENT BUS FOUND:",!!window.pdfjsEventBus);

Check failure on line 390 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Insert `·`
const eventBus = window.pdfjsEventBus || new EventBus();
this.eventBus = AppOptions.eventBus = eventBus

Check failure on line 392 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Insert `;`
this.mlManager?.setEventBus(eventBus, this._globalAbortController.signal);

this.overlayManager = new OverlayManager();
Expand Down Expand Up @@ -1422,14 +1427,15 @@ const PDFViewerApplication = {
this.pdfOutlineViewer.render({ outline, pdfDocument });
});
}
if (this.pdfAttachmentViewer) {
pdfDocument.getAttachments().then(attachments => {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the attachments resolved.
}
this.pdfAttachmentViewer.render({ attachments });
});
}
// THORIUM_BUILD
// if (this.pdfAttachmentViewer) {
// pdfDocument.getAttachments().then(attachments => {
// if (pdfDocument !== this.pdfDocument) {
// return; // The document was closed while the attachments resolved.

Check failure on line 1434 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

This line has a comment length of 81. Maximum allowed is 80
// }
// this.pdfAttachmentViewer.render({ attachments });
// });
// }
if (this.pdfLayerViewer) {
// Ensure that the layers accurately reflects the current state in the
// viewer itself, rather than the default state provided by the API.
Expand All @@ -1444,6 +1450,7 @@ const PDFViewerApplication = {

this._initializePageLabels(pdfDocument);
this._initializeMetadata(pdfDocument);
this.eventBus.dispatch("__pdfdocument", pdfDocument);
},

/**
Expand Down Expand Up @@ -1883,8 +1890,8 @@ const PDFViewerApplication = {

eventBus._on("resize", onResize.bind(this), opts);
eventBus._on("hashchange", onHashchange.bind(this), opts);
eventBus._on("beforeprint", this.beforePrint.bind(this), opts);
eventBus._on("afterprint", this.afterPrint.bind(this), opts);
// eventBus._on("beforeprint", this.beforePrint.bind(this), opts);
// eventBus._on("afterprint", this.afterPrint.bind(this), opts);
eventBus._on("pagerender", onPageRender.bind(this), opts);
eventBus._on("pagerendered", onPageRendered.bind(this), opts);
eventBus._on("updateviewarea", onUpdateViewarea.bind(this), opts);
Expand All @@ -1909,8 +1916,8 @@ const PDFViewerApplication = {
evt => (pdfViewer.annotationEditorMode = evt),
opts
);
eventBus._on("print", this.triggerPrinting.bind(this), opts);
eventBus._on("download", this.downloadOrSave.bind(this), opts);
// eventBus._on("print", this.triggerPrinting.bind(this), opts);
// eventBus._on("download", this.downloadOrSave.bind(this), opts);
eventBus._on("firstpage", () => (this.page = 1), opts);
eventBus._on("lastpage", () => (this.page = this.pagesCount), opts);
eventBus._on("nextpage", () => pdfViewer.nextPage(), opts);
Expand Down Expand Up @@ -1974,8 +1981,8 @@ const PDFViewerApplication = {
);

if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
eventBus._on("fileinputchange", onFileInputChange.bind(this), opts);
eventBus._on("openfile", onOpenFile.bind(this), opts);
// eventBus._on("fileinputchange", onFileInputChange.bind(this), opts);
// eventBus._on("openfile", onOpenFile.bind(this), opts);
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
eventBus._on(
Expand All @@ -1999,6 +2006,56 @@ const PDFViewerApplication = {
opts
);
}


Check failure on line 2010 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Delete `⏎`

Check failure on line 2010 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

More than 1 blank line not allowed
// THORIUM_BUILD
const pageRenderedExtract = async (ev) => {

Check failure on line 2012 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Replace `(ev)` with `ev`
try {
if (ev.pageNumber === 1) {
const page = ev.source;
if (!page || !page.canvas) {
throw Error("PDF PAGE CANVAS??!");

Check failure on line 2017 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Use `new` when creating an error
}

// const img = page?.canvas?.toDataURL("image/png");
const blob = await new Promise((res, _rej) => {
page.canvas.toBlob(
(blob) => {

Check failure on line 2023 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Replace `(blob)` with `blob`

Check failure on line 2023 in web/app.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

'blob' is already declared in the upper scope on line 2021 column 17
res(blob);
},
"image/png",
0.95
);
});
const img = await blob.arrayBuffer();

const doc = this.pdfDocument;
const metadata = await doc.getMetadata();
const numberofpages = doc.numPages;
const numberOfPagesChecked = typeof numberofpages === "number" ? numberofpages : 0;

// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
const data = {
...metadata,
img,
numberofpages: numberOfPagesChecked,
};

// https://www.electronjs.org/docs/api/ipc-renderer#ipcrenderersendchannel-args
// const ipc = require('electron').ipcRenderer;
const ipc = window.electronIpcRenderer;
if (ipc) {
ipc.send("pdfjs-extract-data", data);
}

eventBus._off("pagerendered", pageRenderedExtract);
}
} catch (e) {
console.log("ERROR TO EXTRACT COVER AND METADATA FROM PDF");
console.log("ERROR", e);
}
};
eventBus._on("pagerendered", pageRenderedExtract);
},

bindWindowEvents() {
Expand Down Expand Up @@ -2235,9 +2292,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
// Removing of the following line will not guarantee that the viewer will
// start accepting URLs from foreign origin -- CORS headers on the remote
// server must be properly configured.
if (fileOrigin !== viewerOrigin) {
throw new Error("file origin does not match viewer's");
}

// THORIUM_BUILD
// if (fileOrigin !== viewerOrigin) {
// throw new Error("file origin does not match viewer's");
// }
} catch (ex) {
PDFViewerApplication._documentError("pdfjs-loading-error", {
message: ex.message,
Expand Down
4 changes: 3 additions & 1 deletion web/pdf_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ class PDFPrintServiceFactory {
}

static get supportsPrinting() {
return shadow(this, "supportsPrinting", true);
// THORIUM_BUILD
// return shadow(this, "supportsPrinting", true);
return false;
}

static createPrintService(params) {
Expand Down
7 changes: 4 additions & 3 deletions web/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -336,20 +336,21 @@ body {
#viewerContainer {
overflow: auto;
position: absolute;
inset: var(--toolbar-height) 0 0;
inset: 0 0 0 0;
outline: none;
z-index: 0;
}

#viewerContainer:not(.pdfPresentationMode) {
/* THORIUM_BUILD */
/* #viewerContainer:not(.pdfPresentationMode) {
transition-duration: var(--sidebar-transition-duration);
transition-timing-function: var(--sidebar-transition-timing-function);
}
#outerContainer.sidebarOpen #viewerContainer:not(.pdfPresentationMode) {
inset-inline-start: var(--sidebar-width);
transition-property: inset-inline-start;
}
} */

#sidebarContainer :is(input, button, select) {
font: message-box;
Expand Down
16 changes: 11 additions & 5 deletions web/viewer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<!--
Copyright 2012 Mozilla Foundation
Expand Down Expand Up @@ -29,6 +29,12 @@
<!--#endif-->
<title>PDF.js viewer</title>


<!-- THORIUM_BUILD -->
<script type="text/javascript">
window.electronIpcRenderer = require("electron").ipcRenderer;
</script>

<!--#if MOZCENTRAL-->
<!--#include viewer-snippet-firefox-extension.html-->
<!--#elif CHROME-->
Expand Down Expand Up @@ -98,7 +104,7 @@
<body tabindex="0">
<div id="outerContainer">

<div id="sidebarContainer">
<div id="sidebarContainer" hidden>
<div id="toolbarSidebar" class="toolbarHorizontalGroup">
<div id="toolbarSidebarLeft">
<div id="sidebarViewButtons" class="toolbarHorizontalGroup toggled" role="radiogroup">
Expand Down Expand Up @@ -141,7 +147,7 @@
</div> <!-- sidebarContainer -->

<div id="mainContainer">
<div class="toolbar">
<div class="toolbar" hidden>
<div id="toolbarContainer">
<div id="toolbarViewer" class="toolbarHorizontalGroup">
<div id="toolbarViewerLeft" class="toolbarHorizontalGroup">
Expand Down Expand Up @@ -460,7 +466,7 @@
</div>
</div> <!-- mainContainer -->

<div id="dialogContainer">
<div id="dialogContainer" hidden>
<dialog id="passwordDialog">
<div class="row">
<label for="password" id="passwordText" data-l10n-id="pdfjs-password-label">Enter the password to open this PDF file:</label>
Expand Down Expand Up @@ -689,6 +695,6 @@
</div> <!-- dialogContainer -->

</div> <!-- outerContainer -->
<div id="printContainer"></div>
<div id="printContainer" hidden></div>
</body>
</html>

0 comments on commit 8e914f7

Please sign in to comment.