E-book viewer/Content server: Disallow browser native context menu when right clicking in sandboxed iframes. Fixes #2033530 [E-book viewer: right-clicking in book metadata view opens a context menu](https://bugs.launchpad.net/calibre/+bug/2033530)

This commit is contained in:
Kovid Goyal 2023-09-01 18:55:55 +05:30
parent e1d8b44561
commit fef4b97a03
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -240,6 +240,9 @@ def sandboxed_html(html, style, sandbox):
css = 'html, body { margin: 0; padding: 0; font-family: __FONT__ } p:first-child { margin-top: 0; padding-top: 0; -webkit-margin-before: 0 }'.replace('__FONT__', get_font_family()) css = 'html, body { margin: 0; padding: 0; font-family: __FONT__ } p:first-child { margin-top: 0; padding-top: 0; -webkit-margin-before: 0 }'.replace('__FONT__', get_font_family())
css += style or '' css += style or ''
final_html = f'<!DOCTYPE html><html><head><style>{css}</style></head><body>{html}</body></html>' final_html = f'<!DOCTYPE html><html><head><style>{css}</style></head><body>{html}</body></html>'
# Microsoft Edge does not support srcdoc not does it work using a data URI. # prevent context menu on right click in iframe
ans.addEventListener('load', def(ev):
ev.target.contentWindow.addEventListener('contextmenu', def(e): e.preventDefault();)
)
ans.srcdoc = final_html ans.srcdoc = final_html
return ans return ans