diff --git a/qutebrowser/browser/webpage.py b/qutebrowser/browser/webpage.py index 3f8ee7578..c7a793ab5 100644 --- a/qutebrowser/browser/webpage.py +++ b/qutebrowser/browser/webpage.py @@ -71,12 +71,6 @@ class BrowserPage(QWebPage): # pylint: disable=invalid-name self.javaScriptPrompt = self._javascript_prompt - def shutdown(self,): - """Shutdown the page.""" - self._networkmanager.abort_requests() - self._networkmanager.destroyed.connect(self.deleteLater) - self._networkmanager.deleteLater() - def _javascript_prompt(self, _frame, msg, default): """Override javaScriptPrompt to use the statusbar. diff --git a/qutebrowser/network/networkmanager.py b/qutebrowser/network/networkmanager.py index 20f47f8b2..ed29a29b5 100644 --- a/qutebrowser/network/networkmanager.py +++ b/qutebrowser/network/networkmanager.py @@ -77,8 +77,9 @@ class NetworkManager(QNetworkAccessManager): authenticator.setUser(user) authenticator.setPassword(password) - def abort_requests(self): + def shutdown(self): """Abort all running requests.""" + self.setNetworkAccessible(QNetworkAccessManager.NotAccessible) for request in self._requests: request.abort() diff --git a/qutebrowser/widgets/tabbedbrowser.py b/qutebrowser/widgets/tabbedbrowser.py index 774793624..3db6f5738 100644 --- a/qutebrowser/widgets/tabbedbrowser.py +++ b/qutebrowser/widgets/tabbedbrowser.py @@ -24,7 +24,6 @@ from functools import partial from PyQt5.QtWidgets import QSizePolicy from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSize from PyQt5.QtGui import QIcon -from PyQt5.QtWebKit import QWebSettings import qutebrowser.config.config as config import qutebrowser.commands.utils as cmdutils @@ -262,14 +261,7 @@ class TabbedBrowser(TabWidget): if not url.isEmpty(): qt_ensure_valid(url) self.url_stack.append(url) - # We disable javascript/plugins because that prevents some segfaults - # when quitting it seems. - settings = tab.settings() - settings.setAttribute(QWebSettings.JavascriptEnabled, False) - settings.setAttribute(QWebSettings.JavaEnabled, False) - settings.setAttribute(QWebSettings.PluginsEnabled, False) - tab.blockSignals(True) - tab.stop() + tab.shutdown() self._tabs.remove(tab) self.removeTab(idx) tab.deleteLater() diff --git a/qutebrowser/widgets/webview.py b/qutebrowser/widgets/webview.py index f70c6cc79..ccb725fda 100644 --- a/qutebrowser/widgets/webview.py +++ b/qutebrowser/widgets/webview.py @@ -21,6 +21,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer from PyQt5.QtWidgets import QApplication +from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWebKitWidgets import QWebView, QWebPage import qutebrowser.config.config as config @@ -121,13 +122,6 @@ class WebView(QWebView): url = self.url().toDisplayString() return "WebView(url='{}')".format(elide(url, 50)) - def __del__(self): - # Explicitely releasing the page here seems to prevent some segfaults - # when quitting. - # Copied from: - # https://code.google.com/p/webscraping/source/browse/webkit.py#325 - self.setPage(None) - @property def open_target(self): """Getter for open_target so we can define a setter.""" @@ -274,6 +268,22 @@ class WebView(QWebView): self.open_target = ClickTarget.normal log.mouse.debug("Normal click, setting normal target") + def shutdown(self): + """Shut down the webview.""" + # We disable javascript because that prevents some segfaults when + # quitting it seems. + settings = self.settings() + settings.setAttribute(QWebSettings.JavascriptEnabled, False) + self.stop() + nam = self.page().networkAccessManager() + # Explicitely releasing the page here seems to prevent some segfaults + # when quitting. + # Copied from: + # https://code.google.com/p/webscraping/source/browse/webkit.py#325 + self.setPage(None) + nam.shutdown() + del nam + def openurl(self, url): """Open a URL in the browser.