Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow scripted content in epubs #5741

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions src/plugins/bookPlayer/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import dialogHelper from '../../components/dialogHelper/dialogHelper';
import ServerConnections from '../../components/ServerConnections';
import Screenfull from 'screenfull';
import TableOfContents from './tableOfContents';
import dom from '../../scripts/dom';
import { translateHtml } from '../../scripts/globalize';
import * as userSettings from '../../scripts/settings/userSettings';
import TouchHelper from 'scripts/touchHelper';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';

Expand Down Expand Up @@ -45,7 +45,6 @@ export class BookPlayer {
this.previous = this.previous.bind(this);
this.next = this.next.bind(this);
this.onWindowKeyUp = this.onWindowKeyUp.bind(this);
this.onTouchStart = this.onTouchStart.bind(this);
}

play(options) {
Expand Down Expand Up @@ -156,19 +155,6 @@ export class BookPlayer {
}
}

onTouchStart(e) {
if (!this.loaded || !e.touches || e.touches.length === 0) return;

// epubjs stores pages off the screen or something for preloading
// get the modulus of the touch event to account for the increased width
const touchX = e.touches[0].clientX % dom.getWindowSize().innerWidth;
if (touchX < dom.getWindowSize().innerWidth / 2) {
this.previous();
} else {
this.next();
}
}

onDialogClosed() {
this.stop();
}
Expand All @@ -191,9 +177,12 @@ export class BookPlayer {
this.bindMediaElementEvents();

document.addEventListener('keyup', this.onWindowKeyUp);
this.rendition?.on('keyup', this.onWindowKeyUp);

this.rendition.on('touchstart', this.onTouchStart);
this.rendition.on('keyup', this.onWindowKeyUp);
const player = document.getElementById('bookPlayerContainer');
this.touchHelper = new TouchHelper(player);
Events.on(this.touchHelper, 'swipeleft', () => this.next());
Events.on(this.touchHelper, 'swiperight', () => this.previous());
}

unbindMediaElementEvents() {
Expand All @@ -216,9 +205,9 @@ export class BookPlayer {
}

document.removeEventListener('keyup', this.onWindowKeyUp);

this.rendition?.off('touchstart', this.onTouchStart);
this.rendition?.off('keyup', this.onWindowKeyUp);

this.touchHelper?.destroy();
}

openTableOfContents() {
Expand Down Expand Up @@ -335,9 +324,7 @@ export class BookPlayer {
width: '100%',
height: renderHeight,
// TODO: Add option for scrolled-doc
flow: 'paginated',
// Scripted content is required to allow touch event passthrough in Safari
allowScriptedContent: true
flow: 'paginated'
});

this.currentSrc = downloadHref;
Expand Down
5 changes: 5 additions & 0 deletions src/styles/ios.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
html {
font-size: 82% !important;
}

// Fix touch events being swallowed by the epubjs iframe
#bookPlayer iframe {
pointer-events: none;
}
Loading