mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Prevent un-lloadable resources in link tags (non-CSS stylesheets) from causing the resource loading check to timeout
This commit is contained in:
parent
45fbdbea30
commit
b0cf1e8c05
@ -215,6 +215,7 @@ class Container(ContainerBase):
|
|||||||
resource_template = link_uid + '|{}|'
|
resource_template = link_uid + '|{}|'
|
||||||
xlink_xpath = XPath('//*[@xl:href]')
|
xlink_xpath = XPath('//*[@xl:href]')
|
||||||
link_xpath = XPath('//h:a[@href]')
|
link_xpath = XPath('//h:a[@href]')
|
||||||
|
res_link_xpath = XPath('//h:link[@href]')
|
||||||
|
|
||||||
def link_replacer(base, url):
|
def link_replacer(base, url):
|
||||||
if url.startswith('#'):
|
if url.startswith('#'):
|
||||||
@ -249,6 +250,14 @@ class Container(ContainerBase):
|
|||||||
elif mt in OEB_DOCS:
|
elif mt in OEB_DOCS:
|
||||||
self.virtualized_names.add(name)
|
self.virtualized_names.add(name)
|
||||||
root = self.parsed(name)
|
root = self.parsed(name)
|
||||||
|
for link in res_link_xpath(root):
|
||||||
|
ltype = (link.get('type') or 'text/css').lower()
|
||||||
|
rel = (link.get('rel') or 'stylesheet').lower()
|
||||||
|
if ltype != 'text/css' or rel != 'stylesheet':
|
||||||
|
# This link will not be loaded by the browser anyway
|
||||||
|
# and will causes the resource load check to hang
|
||||||
|
link.attrib.clear()
|
||||||
|
changed.add(name)
|
||||||
rewrite_links(root, partial(link_replacer, name))
|
rewrite_links(root, partial(link_replacer, name))
|
||||||
for a in link_xpath(root):
|
for a in link_xpath(root):
|
||||||
href = a.get('href')
|
href = a.get('href')
|
||||||
|
@ -229,11 +229,13 @@ def unserialize_html(serialized_data, proceed):
|
|||||||
clear(document.head, document.body)
|
clear(document.head, document.body)
|
||||||
load_required = set()
|
load_required = set()
|
||||||
proceeded = False
|
proceeded = False
|
||||||
|
hang_timeout = 5
|
||||||
|
|
||||||
def hangcheck():
|
def hangcheck():
|
||||||
nonlocal proceeded
|
nonlocal proceeded
|
||||||
if not proceeded:
|
if not proceeded:
|
||||||
proceeded = True
|
proceeded = True
|
||||||
|
print('WARNING: All resources did not load in {} seconds, proceeding anyway ({} resources left)'.format(hang_timeout, load_required.length))
|
||||||
proceed()
|
proceed()
|
||||||
|
|
||||||
def onload():
|
def onload():
|
||||||
@ -258,7 +260,7 @@ def unserialize_html(serialized_data, proceed):
|
|||||||
ev.initEvent('DOMContentLoaded', True, True)
|
ev.initEvent('DOMContentLoaded', True, True)
|
||||||
document.dispatchEvent(ev)
|
document.dispatchEvent(ev)
|
||||||
if load_required.length:
|
if load_required.length:
|
||||||
setTimeout(hangcheck, 5000)
|
setTimeout(hangcheck, hang_timeout * 1000)
|
||||||
else:
|
else:
|
||||||
proceeded = True
|
proceeded = True
|
||||||
proceed()
|
proceed()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user