Remove pdfjs.fix_urls

Now that we use qute://pdfjs to show the viewer, we don't need to rewrite any
URLs.
This commit is contained in:
Florian Bruhin 2018-09-06 00:18:09 +02:00
parent 24fb3b0d1b
commit 8f19820a7a
2 changed files with 1 additions and 58 deletions

View File

@ -42,33 +42,6 @@ class PDFJSNotFound(Exception):
super().__init__(message) super().__init__(message)
def fix_urls(asset):
"""Take an html page and replace each relative URL with an absolute.
This is specialized for pdf.js files and not a general purpose function.
Args:
asset: js file or html page as string.
"""
new_urls = [
('viewer.css', 'qute://pdfjs/web/viewer.css'),
('compatibility.js', 'qute://pdfjs/web/compatibility.js'),
('locale/locale.properties',
'qute://pdfjs/web/locale/locale.properties'),
('l10n.js', 'qute://pdfjs/web/l10n.js'),
('../build/pdf.js', 'qute://pdfjs/build/pdf.js'),
('debugger.js', 'qute://pdfjs/web/debugger.js'),
('viewer.js', 'qute://pdfjs/web/viewer.js'),
('compressed.tracemonkey-pldi-09.pdf', ''),
('./images/', 'qute://pdfjs/web/images/'),
('../build/pdf.worker.js', 'qute://pdfjs/build/pdf.worker.js'),
('../web/cmaps/', 'qute://pdfjs/web/cmaps/'),
]
for original, new in new_urls:
asset = asset.replace(original, new)
return asset
SYSTEM_PDFJS_PATHS = [ SYSTEM_PDFJS_PATHS = [
# Debian pdf.js-common # Debian pdf.js-common
# Arch Linux pdfjs (AUR) # Arch Linux pdfjs (AUR)
@ -113,13 +86,7 @@ def get_pdfjs_res_and_path(path):
except FileNotFoundError: except FileNotFoundError:
raise PDFJSNotFound(path) from None raise PDFJSNotFound(path) from None
try: return content, file_path
# Might be script/html or might be binary
text_content = content.decode('utf-8')
except UnicodeDecodeError:
return (content, file_path)
text_content = fix_urls(text_content)
return (text_content.encode('utf-8'), file_path)
def get_pdfjs_res(path): def get_pdfjs_res(path):

View File

@ -17,35 +17,11 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import textwrap
import pytest import pytest
from PyQt5.QtCore import QUrl
from qutebrowser.browser import pdfjs from qutebrowser.browser import pdfjs
def test_fix_urls():
page = textwrap.dedent("""
<html>
<script src="viewer.js"></script>
<link href="viewer.css">
<script src="unrelated.js"></script>
</html>
""").strip()
expected = textwrap.dedent("""
<html>
<script src="qute://pdfjs/web/viewer.js"></script>
<link href="qute://pdfjs/web/viewer.css">
<script src="unrelated.js"></script>
</html>
""").strip()
actual = pdfjs.fix_urls(page)
assert actual == expected
@pytest.mark.parametrize('path, expected', [ @pytest.mark.parametrize('path, expected', [
('web/viewer.js', 'viewer.js'), ('web/viewer.js', 'viewer.js'),
('build/locale/foo.bar', 'locale/foo.bar'), ('build/locale/foo.bar', 'locale/foo.bar'),