diff --git a/qutebrowser/app.py b/qutebrowser/app.py index b88745ba3..8f08e4c84 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -61,8 +61,6 @@ class Application(QApplication): cmd_history: The "cmd_history" LineConfigParser instance. messagebridge: The global MessageBridge instance. modeman: The global ModeManager instance. - cookiejar: The global CookieJar instance. - cache: The global DiskCache instance. rl_bridge: The ReadlineBridge being used. args: ArgumentParser instance. _commandrunner: The main CommandRunner instance. @@ -131,9 +129,11 @@ class Application(QApplication): log.init.debug("Initializing utility commands...") utilcmds.init() log.init.debug("Initializing cookies...") - self.cookiejar = cookies.CookieJar(self) + cookiejar = cookies.CookieJar(self) + self.obj.register('cookiejar', cookiejar) log.init.debug("Initializing cache...") - self.cache = cache.DiskCache(self) + diskcache = cache.DiskCache(self) + self.obj.register('cache', diskcache) log.init.debug("Initializing commands...") self._commandrunner = runners.CommandRunner() log.init.debug("Initializing search...") @@ -756,8 +756,12 @@ class Application(QApplication): to_save.append(("command history", self.cmd_history.save)) if hasattr(self, 'stateconfig'): to_save.append(("window geometry", self.stateconfig.save)) - if hasattr(self, 'cookiejar'): - to_save.append(("cookies", self.cookiejar.save)) + try: + cookiejar = self.obj.get('cookiejar') + except KeyError: + pass + else: + to_save.append(("cookies", cookiejar.save)) for what, handler in to_save: log.destroy.debug("Saving {} (handler: {})".format( what, handler.__qualname__)) diff --git a/qutebrowser/network/networkmanager.py b/qutebrowser/network/networkmanager.py index 33852fffd..bb7eaa708 100644 --- a/qutebrowser/network/networkmanager.py +++ b/qutebrowser/network/networkmanager.py @@ -51,13 +51,17 @@ class NetworkManager(QNetworkAccessManager): self._scheme_handlers = { 'qute': qutescheme.QuteSchemeHandler(), } + + # We have a shared cookie jar and cache - we restore their parents so + # we don't take ownership of them. app = QCoreApplication.instance() - self.setCookieJar(app.cookiejar) - self.setCache(app.cache) - # We have a shared cookie jar and cache , so we don't want the - # NetworkManager to take ownership of them. - app.cookiejar.setParent(app) - app.cache.setParent(app) + cookiejar = utils.get_object('cookiejar') + self.setCookieJar(cookiejar) + cookiejar.setParent(app) + cache = utils.get_object('cache') + self.setCache(cache) + cache.setParent(app) + if SSL_AVAILABLE: self.sslErrors.connect(self.on_ssl_errors) self.authenticationRequired.connect(self.on_authentication_required) diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 34a9487a8..7f91d1fe5 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -388,6 +388,10 @@ class ObjectRegistry: """A registry of long-living objects in qutebrowser. Inspired by the eric IDE code (E5Gui/E5Application.py). + + Objects registered globally: + cookiejar: CookieJar instance. + cache: DiskCache instance. """ def __init__(self):