Clean up tab shutdown.
This commit is contained in:
parent
142fe19d11
commit
f19a1db120
@ -71,12 +71,6 @@ class BrowserPage(QWebPage):
|
|||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
self.javaScriptPrompt = self._javascript_prompt
|
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):
|
def _javascript_prompt(self, _frame, msg, default):
|
||||||
"""Override javaScriptPrompt to use the statusbar.
|
"""Override javaScriptPrompt to use the statusbar.
|
||||||
|
|
||||||
|
@ -77,8 +77,9 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
authenticator.setUser(user)
|
authenticator.setUser(user)
|
||||||
authenticator.setPassword(password)
|
authenticator.setPassword(password)
|
||||||
|
|
||||||
def abort_requests(self):
|
def shutdown(self):
|
||||||
"""Abort all running requests."""
|
"""Abort all running requests."""
|
||||||
|
self.setNetworkAccessible(QNetworkAccessManager.NotAccessible)
|
||||||
for request in self._requests:
|
for request in self._requests:
|
||||||
request.abort()
|
request.abort()
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ from functools import partial
|
|||||||
from PyQt5.QtWidgets import QSizePolicy
|
from PyQt5.QtWidgets import QSizePolicy
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSize
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSize
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtWebKit import QWebSettings
|
|
||||||
|
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
import qutebrowser.commands.utils as cmdutils
|
import qutebrowser.commands.utils as cmdutils
|
||||||
@ -262,14 +261,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
if not url.isEmpty():
|
if not url.isEmpty():
|
||||||
qt_ensure_valid(url)
|
qt_ensure_valid(url)
|
||||||
self.url_stack.append(url)
|
self.url_stack.append(url)
|
||||||
# We disable javascript/plugins because that prevents some segfaults
|
tab.shutdown()
|
||||||
# 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()
|
|
||||||
self._tabs.remove(tab)
|
self._tabs.remove(tab)
|
||||||
self.removeTab(idx)
|
self.removeTab(idx)
|
||||||
tab.deleteLater()
|
tab.deleteLater()
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from PyQt5.QtWebKit import QWebSettings
|
||||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||||
|
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
@ -121,13 +122,6 @@ class WebView(QWebView):
|
|||||||
url = self.url().toDisplayString()
|
url = self.url().toDisplayString()
|
||||||
return "WebView(url='{}')".format(elide(url, 50))
|
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
|
@property
|
||||||
def open_target(self):
|
def open_target(self):
|
||||||
"""Getter for open_target so we can define a setter."""
|
"""Getter for open_target so we can define a setter."""
|
||||||
@ -274,6 +268,22 @@ class WebView(QWebView):
|
|||||||
self.open_target = ClickTarget.normal
|
self.open_target = ClickTarget.normal
|
||||||
log.mouse.debug("Normal click, setting normal target")
|
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):
|
def openurl(self, url):
|
||||||
"""Open a URL in the browser.
|
"""Open a URL in the browser.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user