Move pdfjs error page to pdfjs.py

This commit is contained in:
Florian Bruhin 2018-09-05 23:18:04 +02:00
parent 36b2f5e63f
commit 8f1690eff7
2 changed files with 6 additions and 7 deletions

View File

@ -24,7 +24,7 @@ import os
from PyQt5.QtCore import QUrl
from qutebrowser.utils import utils, javascript
from qutebrowser.utils import utils, javascript, jinja
class PDFJSNotFound(Exception):
@ -49,6 +49,10 @@ def generate_pdfjs_page(url):
Args:
url: The url of the pdf as QUrl.
"""
if not is_available():
return jinja.render('no_pdfjs.html',
url=url.toDisplayString(),
title="PDF.js not found")
viewer = get_pdfjs_res('web/viewer.html').decode('utf-8')
script = _generate_pdfjs_script(url)
html_page = viewer.replace('</body>',

View File

@ -208,12 +208,7 @@ class BrowserPage(QWebPage):
def _show_pdfjs(self, reply):
"""Show the reply with pdfjs."""
try:
page = pdfjs.generate_pdfjs_page(reply.url())
except pdfjs.PDFJSNotFound:
page = jinja.render('no_pdfjs.html',
url=reply.url().toDisplayString(),
title="PDF.js not found")
page = pdfjs.generate_pdfjs_page(reply.url())
self.mainFrame().setContent(page.encode('utf-8'), 'text/html',
reply.url())
reply.deleteLater()