mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Couple more places where we need to restrict what JS from the ebook can do
This commit is contained in:
parent
6d90650808
commit
3cdc7a8096
@ -29,6 +29,7 @@ class DRMError(ValueError):
|
|||||||
class ParserError(ValueError):
|
class ParserError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'txtz', 'text', 'htm', 'xhtm',
|
BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'txtz', 'text', 'htm', 'xhtm',
|
||||||
'html', 'htmlz', 'xhtml', 'pdf', 'pdb', 'updb', 'pdr', 'prc', 'mobi', 'azw', 'doc',
|
'html', 'htmlz', 'xhtml', 'pdf', 'pdb', 'updb', 'pdr', 'prc', 'mobi', 'azw', 'doc',
|
||||||
'epub', 'fb2', 'djv', 'djvu', 'lrx', 'cbr', 'cbz', 'cbc', 'oebzip',
|
'epub', 'fb2', 'djv', 'djvu', 'lrx', 'cbr', 'cbz', 'cbc', 'oebzip',
|
||||||
@ -164,6 +165,7 @@ def render_html_data(path_to_html, width, height):
|
|||||||
|
|
||||||
def render_html(path_to_html, width=590, height=750, as_xhtml=True):
|
def render_html(path_to_html, width=590, height=750, as_xhtml=True):
|
||||||
from PyQt5.QtWebKitWidgets import QWebPage
|
from PyQt5.QtWebKitWidgets import QWebPage
|
||||||
|
from PyQt5.QtWebKit import QWebSettings
|
||||||
from PyQt5.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
|
from PyQt5.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
|
||||||
from calibre.gui2 import is_ok_to_use_qt
|
from calibre.gui2 import is_ok_to_use_qt
|
||||||
if not is_ok_to_use_qt():
|
if not is_ok_to_use_qt():
|
||||||
@ -172,7 +174,11 @@ def render_html(path_to_html, width=590, height=750, as_xhtml=True):
|
|||||||
with CurrentDir(os.path.dirname(path_to_html)):
|
with CurrentDir(os.path.dirname(path_to_html)):
|
||||||
page = QWebPage()
|
page = QWebPage()
|
||||||
settings = page.settings()
|
settings = page.settings()
|
||||||
settings.setAttribute(settings.PluginsEnabled, False)
|
settings.setAttribute(QWebSettings.JavaEnabled, False)
|
||||||
|
settings.setAttribute(QWebSettings.PluginsEnabled, False)
|
||||||
|
settings.setAttribute(QWebSettings.JavascriptCanOpenWindows, False)
|
||||||
|
settings.setAttribute(QWebSettings.JavascriptCanAccessClipboard, False)
|
||||||
|
settings.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, False) # ensure javascript cannot read from local files
|
||||||
pal = page.palette()
|
pal = page.palette()
|
||||||
pal.setBrush(QPalette.Background, Qt.white)
|
pal.setBrush(QPalette.Background, Qt.white)
|
||||||
page.setPalette(pal)
|
page.setPalette(pal)
|
||||||
@ -225,6 +231,7 @@ def calibre_cover(title, author_string, series_string=None,
|
|||||||
ans = calibre_cover2(title, author_string or '', series_string or '', logo_path=logo_path, as_qimage=True)
|
ans = calibre_cover2(title, author_string or '', series_string or '', logo_path=logo_path, as_qimage=True)
|
||||||
return image_to_data(ans, fmt=output_format)
|
return image_to_data(ans, fmt=output_format)
|
||||||
|
|
||||||
|
|
||||||
UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc|rem|q)$')
|
UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc|rem|q)$')
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,6 +74,11 @@ class Page(QWebPage): # {{{
|
|||||||
opts.pdf_mono_font_size)
|
opts.pdf_mono_font_size)
|
||||||
settings.setFontSize(QWebSettings.MinimumLogicalFontSize, 8)
|
settings.setFontSize(QWebSettings.MinimumLogicalFontSize, 8)
|
||||||
settings.setFontSize(QWebSettings.MinimumFontSize, 8)
|
settings.setFontSize(QWebSettings.MinimumFontSize, 8)
|
||||||
|
settings.setAttribute(QWebSettings.JavaEnabled, False)
|
||||||
|
settings.setAttribute(QWebSettings.PluginsEnabled, False)
|
||||||
|
settings.setAttribute(QWebSettings.JavascriptCanOpenWindows, False)
|
||||||
|
settings.setAttribute(QWebSettings.JavascriptCanAccessClipboard, False)
|
||||||
|
settings.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, False) # ensure javascript cannot read from local files
|
||||||
|
|
||||||
std = {'serif':opts.pdf_serif_family, 'sans':opts.pdf_sans_family,
|
std = {'serif':opts.pdf_serif_family, 'sans':opts.pdf_sans_family,
|
||||||
'mono':opts.pdf_mono_family}.get(opts.pdf_standard_font,
|
'mono':opts.pdf_mono_family}.get(opts.pdf_standard_font,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user