Skip to content

Commit

Permalink
MV3: fix regressions with the iframe refactor
Browse files Browse the repository at this point in the history
  - Open the 'Access denied' page in a new tab
  - Allow fullscreen to enable presentation mode
  - Better handle links when made default viewer
  - Close viewer frame after showing error message
  • Loading branch information
shivaprsd committed Dec 15, 2024
1 parent 77dbde5 commit ff3f688
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doqment",
"version": "0.9.1",
"version": "0.9.2",
"description": "Mozilla's HTML5 PDF Viewer with Reader-mode add-on.",
"homepage": "https://github.com/shivaprsd/doqment",
"repository": "github:shivaprsd/doqment",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest-v2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 2,
"version": "0.9.1",
"version": "0.9.2",

"name": "doqment PDF Reader",
"short_name": "doqment",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest-v3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 3,
"version": "0.9.1",
"version": "0.9.2",
"minimum_chrome_version": "116",

"name": "doqment PDF Reader",
Expand Down
2 changes: 1 addition & 1 deletion src/pdfjs
Submodule pdfjs updated 62 files
+2 −2 VERSION
+2,056 −6,215 build/pdf.mjs
+1 −1 build/pdf.mjs.map
+5 −3,592 build/pdf.sandbox.mjs
+1 −1 build/pdf.sandbox.mjs.map
+11,273 −16,268 build/pdf.worker.mjs
+1 −1 build/pdf.worker.mjs.map
+15 −1 web/locale/be/viewer.ftl
+1 −0 web/locale/bg/viewer.ftl
+15 −1 web/locale/cs/viewer.ftl
+15 −1 web/locale/cy/viewer.ftl
+16 −2 web/locale/da/viewer.ftl
+15 −1 web/locale/de/viewer.ftl
+15 −1 web/locale/dsb/viewer.ftl
+15 −1 web/locale/el/viewer.ftl
+15 −1 web/locale/en-GB/viewer.ftl
+21 −0 web/locale/en-US/viewer.ftl
+15 −1 web/locale/es-AR/viewer.ftl
+15 −1 web/locale/es-CL/viewer.ftl
+15 −1 web/locale/es-ES/viewer.ftl
+15 −1 web/locale/eu/viewer.ftl
+15 −1 web/locale/fi/viewer.ftl
+15 −1 web/locale/fr/viewer.ftl
+4 −0 web/locale/fur/viewer.ftl
+16 −2 web/locale/fy-NL/viewer.ftl
+21 −1 web/locale/gn/viewer.ftl
+16 −2 web/locale/he/viewer.ftl
+31 −2 web/locale/hr/viewer.ftl
+15 −1 web/locale/hsb/viewer.ftl
+15 −1 web/locale/hu/viewer.ftl
+15 −1 web/locale/ia/viewer.ftl
+15 −1 web/locale/is/viewer.ftl
+21 −1 web/locale/it/viewer.ftl
+15 −0 web/locale/ja/viewer.ftl
+15 −1 web/locale/kk/viewer.ftl
+15 −1 web/locale/ko/viewer.ftl
+15 −1 web/locale/nb-NO/viewer.ftl
+15 −1 web/locale/nl/viewer.ftl
+6 −6 web/locale/nn-NO/viewer.ftl
+15 −1 web/locale/pa-IN/viewer.ftl
+15 −1 web/locale/pl/viewer.ftl
+15 −1 web/locale/pt-BR/viewer.ftl
+4 −0 web/locale/pt-PT/viewer.ftl
+15 −1 web/locale/rm/viewer.ftl
+15 −1 web/locale/ru/viewer.ftl
+5 −1 web/locale/si/viewer.ftl
+15 −1 web/locale/sk/viewer.ftl
+15 −1 web/locale/sl/viewer.ftl
+22 −2 web/locale/sq/viewer.ftl
+3 −3 web/locale/sr/viewer.ftl
+15 −1 web/locale/sv-SE/viewer.ftl
+15 −1 web/locale/tg/viewer.ftl
+15 −1 web/locale/th/viewer.ftl
+15 −1 web/locale/tr/viewer.ftl
+15 −1 web/locale/uk/viewer.ftl
+15 −1 web/locale/vi/viewer.ftl
+16 −2 web/locale/zh-CN/viewer.ftl
+15 −1 web/locale/zh-TW/viewer.ftl
+303 −120 web/viewer.css
+15 −1 web/viewer.html
+193 −3,870 web/viewer.mjs
+1 −1 web/viewer.mjs.map
1 change: 1 addition & 0 deletions src/scripts/doqment.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const Doqment = {
window.alert(details.message);
app.loadingBar?.hide();
app.close();
chrome.runtime.sendMessage({ action: "removeViewer" });
},

/* Smart zoom */
Expand Down
34 changes: 20 additions & 14 deletions src/scripts/mv3/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,25 @@ async function handleClick(info, tab) {
/* if doqment is the default, open in the built-in viewer instead */
async function openLink(url, openerTabId) {
const permit = { origins: [url] };
let viewerUrl;
if (!url.startsWith(baseUrl) && await chrome.permissions.request(permit)) {
viewerUrl = getViewerURL(baseUrl, url);
const allowed = await chrome.permissions.request(permit).catch(r => {});
if (allowed === false) {
return;
}
const isViewerUrl = url.startsWith(baseUrl);
const scripts = await chrome.scripting.getRegisteredContentScripts();
/* We cannot check this earlier because `permissions.request()`
* has to be called immediately after user action where needed */
if (scripts.length > 0) {
if (isViewerUrl) {
url = new URL(url).searchParams.get("file");
}
url = new URL(url);
url.searchParams.set("doqment", "ignore");
chrome.tabs.create({ url: url.toString(), openerTabId });
} else if (viewerUrl) {
} else {
const newTab = await chrome.tabs.create({ url, openerTabId });
loadViewer(viewerUrl, newTab.id);
if (allowed)
loadViewer(getViewerURL(baseUrl, url), newTab.id);
}
}

Expand Down Expand Up @@ -106,13 +111,17 @@ function toggleAutoOpen(enable, menuId) {
}

function respond(request, sender, sendResponse) {
const tabId = sender.tab.id;
if (request.action === "loadViewer") {
const viewerUrl = getViewerURL(baseUrl, request.body);
if (sender.frameId === 0) {
loadViewer(viewerUrl, sender.tab.id);
loadViewer(viewerUrl, tabId);
} else {
sendResponse({ url: viewerUrl });
}
} else if (request.action === "removeViewer") {
const func = () => document.getElementById("doqmentViewer").remove();
chrome.scripting.executeScript({ target: {tabId}, func });
}
}

Expand Down Expand Up @@ -179,18 +188,14 @@ async function newViewer(tab) {
return chrome.extension.isAllowedFileSchemeAccess();
};
const url = tab.url;
let viewerUrl;
let viewerUrl = splashUrl;
if (new URL(url).protocol === "file:" && !await hasFilesAccess()) {
viewerUrl = messageUrl;
} else if (await isPdfTab(tab.id)) {
viewerUrl = getViewerURL(baseUrl, url);
}

if (viewerUrl) {
loadViewer(viewerUrl, tab.id);
} else {
chrome.tabs.create({ url: splashUrl, index: tab.index + 1 });
loadViewer(getViewerURL(baseUrl, url), tab.id);
return;
}
chrome.tabs.create({ url: viewerUrl, index: tab.index + 1 });
}

/* Load viewer in a full page frame in the given tab */
Expand All @@ -199,6 +204,7 @@ function loadViewer(viewerUrl, tabId) {
const frame = document.createElement("iframe");
frame.src = src;
frame.id = "doqmentViewer";
frame.setAttribute("allow", "fullscreen");
document.body.prepend(frame);
};
chrome.scripting.executeScript({
Expand Down

0 comments on commit ff3f688

Please sign in to comment.