Clean up tab shutdown.

This commit is contained in:
Florian Bruhin 2014-08-01 23:23:31 +02:00
parent 142fe19d11
commit f19a1db120
4 changed files with 20 additions and 23 deletions

View File

@ -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.

View File

@ -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()

View File

@ -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()

View File

@ -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.