diff --git a/MANIFEST.in b/MANIFEST.in
index 847a67c12..963df0098 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -5,7 +5,7 @@ recursive-include qutebrowser/html *.html
recursive-include qutebrowser/img *.svg *.png
recursive-include qutebrowser/test *.py
recursive-include qutebrowser/javascript *.js
-graft qutebrowser/pdfjs
+graft qutebrowser/3rdparty
graft icons
graft doc/img
graft misc
diff --git a/README.asciidoc b/README.asciidoc
index 04292e0fa..3d4160d2d 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -275,7 +275,7 @@ along with this program. If not, see .
pdf.js
------
-Qutebrowser uses https://github.com/mozilla/pdf.js/[pdf.js] to display
+qutebrowser uses https://github.com/mozilla/pdf.js/[pdf.js] to display
PDF files in the browser.
pdf.js is distributed under the terms of the Apache License. You can
diff --git a/qutebrowser/browser/network/qutescheme.py b/qutebrowser/browser/network/qutescheme.py
index bf1cb8d6d..9b96ca468 100644
--- a/qutebrowser/browser/network/qutescheme.py
+++ b/qutebrowser/browser/network/qutescheme.py
@@ -37,15 +37,13 @@ from PyQt5.QtNetwork import QNetworkReply
from PyQt5.QtWebKit import QWebSecurityOrigin
import qutebrowser
+from qutebrowser.browser import pdfjs
from qutebrowser.browser.network import schemehandler, networkreply
from qutebrowser.utils import (version, utils, jinja, log, message, docutils,
objreg)
from qutebrowser.config import configexc, configdata
-QWebSecurityOrigin.addLocalScheme('qute')
-
-
pyeval_output = ":pyeval was never called"
@@ -211,5 +209,12 @@ def qute_settings(win_id, _request):
def qute_pdfjs(_win_id, request):
"""Handler for qute://pdfjs. Return the pdf.js viewer."""
urlpath = request.url().path().lstrip('/')
- res_path = 'pdfjs/{}'.format(urlpath)
- return utils.read_file(res_path, binary=True)
+ res_path = '3rdparty/pdfjs/{}'.format(urlpath)
+ content = utils.read_file(res_path, binary=True)
+ try:
+ # Might be script/html or might be binary
+ text_content = content.decode('utf-8')
+ except UnicodeDecodeError:
+ return content
+ text_content = pdfjs.fix_urls(text_content)
+ return text_content.encode('utf-8')
diff --git a/qutebrowser/browser/pdfjs.py b/qutebrowser/browser/pdfjs.py
new file mode 100644
index 000000000..ec3da5fa8
--- /dev/null
+++ b/qutebrowser/browser/pdfjs.py
@@ -0,0 +1,80 @@
+# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
+
+# Copyright 2015 Daniel Schadt
+#
+# This file is part of qutebrowser.
+#
+# qutebrowser is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# qutebrowser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with qutebrowser. If not, see .
+
+"""pdf.js integration for qutebrowser."""
+
+from qutebrowser.browser import webelem
+from qutebrowser.utils import utils
+
+
+def generate_pdfjs_page(url):
+ """Return the html content of a page that displays url with pdfjs.
+
+ Returns a string.
+
+ Args:
+ url: The url of the pdf as QUrl.
+ """
+ viewer = utils.read_file('3rdparty/pdfjs/web/viewer.html')
+ viewer = fix_urls(viewer)
+ script = _generate_pdfjs_script(url)
+ html_page = viewer.replace(
+ '