diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 145bc9c44..dfa5ed6bc 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -700,6 +700,12 @@ class WebEngineTab(browsertab.AbstractTab): self._inject_early_js('js', js_code, subframes=True) self._init_stylesheet() + js_code_print = utils.read_file('javascript/print.js') + self._inject_early_js('js', + js_code_print, + subframes=True, + world=QWebEngineScript.MainWorld) + greasemonkey = objreg.get('greasemonkey') greasemonkey.scripts_reloaded.connect(self._inject_userscripts) self._inject_userscripts() diff --git a/qutebrowser/browser/webengine/webview.py b/qutebrowser/browser/webengine/webview.py index 70cd11e0d..8483610d1 100644 --- a/qutebrowser/browser/webengine/webview.py +++ b/qutebrowser/browser/webengine/webview.py @@ -48,7 +48,7 @@ class WebEngineView(QWebEngineView): else: profile = webenginesettings.default_profile page = WebEnginePage(theme_color=theme_color, profile=profile, - parent=self) + parent=self, win_id=win_id) self.setPage(page) def shutdown(self): @@ -130,7 +130,7 @@ class WebEnginePage(QWebEnginePage): shutting_down = pyqtSignal() navigation_request = pyqtSignal(usertypes.NavigationRequest) - def __init__(self, *, theme_color, profile, parent=None): + def __init__(self, *, theme_color, profile, win_id, parent=None): super().__init__(profile, parent) self._is_shutting_down = False self.featurePermissionRequested.connect( @@ -138,6 +138,7 @@ class WebEnginePage(QWebEnginePage): self._theme_color = theme_color self._set_bg_color() config.instance.changed.connect(self._set_bg_color) + self._win_id = win_id self.urlChanged.connect(self._inject_userjs) @config.change_filter('colors.webpage.bg') @@ -310,9 +311,17 @@ class WebEnginePage(QWebEnginePage): QWebEnginePage.NavigationTypeOther: usertypes.NavigationRequest.Type.other, } + accept_request = True + if(url.scheme() == "qute" and url.path() == "print"): + command_dispatcher = objreg.get('command-dispatcher', + scope='window', + window=self._win_id) + command_dispatcher.printpage() + accept_request = False navigation = usertypes.NavigationRequest(url=url, navigation_type=type_map[typ], - is_main_frame=is_main_frame) + is_main_frame=is_main_frame, + accepted=accept_request) self.navigation_request.emit(navigation) return navigation.accepted diff --git a/qutebrowser/javascript/print.js b/qutebrowser/javascript/print.js new file mode 100644 index 000000000..20e1dadce --- /dev/null +++ b/qutebrowser/javascript/print.js @@ -0,0 +1,24 @@ +/** + * Copyright 2018 Florian Bruhin (The Compiler) + * + * 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 . + */ + +"use strict"; + +window.print = function() { + window.location = "qute:print"; +};